Usage: rename perlexpr direpath
#!/usr/bin/perl -w
if($#ARGV !=1)
{
print "Usage: rename perlexpr direpath\n";
print "ex. rename s/exe/html c:/test";
exit(0);
}
$regexp=shift ;
$dir=shift;
opendir(DIR, "$dir");
@files = readdir(DIR);
closedir(DIR);
foreach $_ (@files) {
$file=$_;
print "file-->$file\n";
eval $regexp;
die $@ if $@;
$path="$dir/$file";
print "$path\n";
rename($path,"$dir/$_" ) unless $file eq $_;
}
No comments:
Post a Comment