50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace astropenguin\botanical;
|
|
|
|
error_reporting ( E_ALL^E_NOTICE ) ;
|
|
|
|
spl_autoload_register(function ( $name )
|
|
{
|
|
require_once str_replace( '\\', '/', "$name.php" );
|
|
});
|
|
|
|
//----------- Usage -----------
|
|
|
|
if ( !$argv[1] )
|
|
die (<<<__USAGE__
|
|
Usage: php {$argv[0]} [options] [-d directory] [-p patterns] [-s "first match" "second" ...] [...args]
|
|
|
|
-d <paths> Directories to look over
|
|
-p <patterns> Define RegEx patterns
|
|
-r Rename file recursively
|
|
-s <str ...> Strings that will replace the matches
|
|
|
|
Optional:
|
|
-e <patterns> Exclude defined pattern
|
|
-l <File> Output log file
|
|
-t Test without modifying anything
|
|
|
|
Example:
|
|
php regRename.php -d ~/ -p "/(.+)_.+/" -s "\\1"
|
|
|
|
Result:
|
|
R File ".mysql_history" will be renamed to ".mysql"
|
|
R File ".db_pass" will be renamed to ".db"
|
|
R File ".bash_logout" will be renamed to ".bash"
|
|
R File ".mysql_pass" will be renamed to ".mysql"
|
|
R File ".bash_history" will be renamed to ".bash"
|
|
|
|
php regRename.php -d ~/ -p "/(.+)_.+/" -s "\\1"
|
|
|
|
__USAGE__
|
|
) ;
|
|
|
|
//------- End Usage -----------
|
|
|
|
$rrgr = new RegRename();
|
|
Args::PARSE ( $argv, array($rrgr, 'setOption') );
|
|
$rrgr->begin();
|
|
|
|
|