4 ###APPDATE: Sun Mar 30 12:46:15 2008
6 ###APPDESC: rename files using perl regexp
7 ###APPUSAGE: [-t] (pattern|func) (files...)
8 ###APPEXAMPLE: renameext -t 's/^.*(\d+)\.jpg/$1' *\n\trenameext -t 'ucfirst' *
9 ###APPOPTION: -t:Test Mode
11 $ARGV[0]="-h" unless(@ARGV);
12 use lib
$ENV{XR_PERL_MODULE_DIR
};
13 use MyPlace
::Script
::Usage qw
/help_even_empty format_help/;
15 exit 0 if(help_even_empty
($0,@ARGV));
20 my $utf8 = find_encoding
("utf8");
24 push @ARGV,$utf8->decode($_);
26 binmode STDERR
,'utf8';
27 binmode STDOUT
,'utf8';
32 $exp=shift,$test="true" if($exp eq "-t");
33 if($exp =~ /\/.*\
//) {
39 $r =~ ' . "$exp" . ' if(\$r);
50 $r = ' . "$exp" . ' $r;
64 rename $old,"$tempname" or return undef;
65 rename "$tempname",$new or return undef;
74 print STDERR
"Please input filenames:\n";
83 foreach my $old(grep !/^\.\.?$/,@files) {
84 my $new = &s_code
($old);
90 print STDERR
$dfile,"\"$old\"\n\t->\"$new\" [Failed:File exists]\n";
94 print STDERR
("\"$old\"\n\t->\"$new\" (Test only) [Sucessed!]\n");
97 if(&my_rename
($old,$new)) {
98 print STDERR
("\"$old\"\n\t->\"$new\" [Sucessed!]\n");
101 print STDERR
("\"$old\"\n\t->\"$new\" [Failed:$!]\n");