#!/usr/perl
#批量修改文件名前缀
foreach my$file (glob "*.mp3")
{
#查找当前目录下所有以“mp3”为前缀的文件
$file =~ /(\d{1,4})[^\d]{0,2}\.mp3$/;
if(length($1) == 0)
{
print "wrong file ".$file."\n";
exit;
}
my $newFile = $1.".mp3";
if(-e $newFile)
{ #如果修改后会导致文件重名,则输出警告,不作处理
warn "Can't rename $file to $newFile. The $newFile exists!\n";
}
else
{
print $file." will be renamed to ".$newFile."\n";
if(1)
{
rename $file, $newFile #重命名文件
or
warn "Rename $file to $newFile failed: $!\n"; #如果重命名失败,则输出警告
}
}
}
阅读(594) | 评论(0) | 转发(0) |