perl批量改文件后缀
如题,perl批量改文件后缀,将已有的统一格式的文件后缀,修改为新的统一的文件后缀。
perl
#!/bin/perl
use 5.010;
print "Please input file suffix which U want to rename!\n";
chomp (my $suffix_old = <>); # 去除输入中的回车符
print "Please output file suffix which U want to rename!\n";
chomp (my $suffix_new = <>);
foreach my $file(glob "*.$suffix_old") {
my $new_file = $file;
$new_file =~ s/\.$suffix_old/.$suffix_new/gm;
if (-e $new_file) {
warn "Cannot rename $file to $new_file: $new_file exists\n";
} elsif (rename $file => $new_file) {
} else {
warn "rename $file to $new_file failed:$!";
}
}