rename批量更名的perl腳本

########################2010. jordan.sg  #
use strict;
use File::Find;
use   Cwd;
my $path = getcwd();
open(LOG, ">error.log") or die "open log file fail!";
print LOG "\n";
#my $object_count = 0;


sub wanted {
	#print  "wanted $File::Find::name\n";
    if ( -f $File::Find::name ) {
        if ( $File::Find::name =~ /t\.txt$/ ) {
                print LOG "$File::Find::name\n";
	    my $srcfile= $File::Find::name;
            my $file = $_;
	         print LOG "- $_\n";
            $file =~ s/t\.txt//; 
			print LOG "> $file\n";
            rename($srcfile, $file); 
        }
    }
	#$obj_count++;
}

find( \&wanted, $path );


#print LOG "rename $obj_count files\n";   ##打印處理文件數
close(LOG);
#$File::Find::dir :當前路徑名 
#$_ :當前文件名不包含路徑
#$File::Find::name :全路徑的當前文件名
相關文章
相關標籤/搜索