utils/php/regRename.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2014-01-23 12:48:52 +00:00
<?php
error_reporting ( E_ALL^E_NOTICE ) ;
2014-07-22 06:39:43 +00:00
require_once dirname( __FILE__ ) . '/astropenguin/package.php';
use astropenguin\botanical\RegRename;
use astropenguin\botanical\Args;
2014-01-23 12:48:52 +00:00
2014-04-11 22:39:53 +00:00
2014-01-23 12:48:52 +00:00
//----------- Usage -----------
if ( !$argv[1] )
2014-04-11 22:39:53 +00:00
die (<<<__USAGE__
Usage: php {$argv[0]} [options] [-d directory] [-p patterns] [-s "first match" "second" ...] [...args]
2014-01-23 12:48:52 +00:00
-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
2014-01-23 12:48:52 +00:00
-t Test without modifying anything
2014-04-11 22:39:53 +00:00
Example:
php regRename.php -d ~/ -p "/(.+)_.+/" -s "\\1"
2014-01-23 12:48:52 +00:00
2014-04-11 22:39:53 +00:00
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"
2014-01-23 12:48:52 +00:00
2014-04-11 22:39:53 +00:00
php regRename.php -d ~/ -p "/(.+)_.+/" -s "\\1"
2014-01-23 12:48:52 +00:00
2014-04-11 22:39:53 +00:00
__USAGE__
) ;
2014-04-11 22:39:53 +00:00
//------- End Usage -----------
$rrgr = new RegRename();
2014-04-11 22:39:53 +00:00
Args::PARSE ( $argv, array($rrgr, 'setOption') );
$rrgr->begin();
2014-04-11 22:39:53 +00:00