$dir = "/home/naveen/mp3tag/testfolder";
opendir(DMP3, $dir) || die("Cannot open directory");
@files= readdir(DMP3;
foreach $f (@files)
{
unless ( ($f eq ".") || ($f eq "..") )
{
$oldfile = $f;
$newfile = $f;
$newfile =~ s/ /_/g;
print "Old file: $oldfile \t";
print "New file: $newfile";
print "\n";
rename ("$oldfile", "$newfile") or warn "Couldn't rename $oldfile to $newfile !\n";
}
}
我正在编写一个简单的程序来为现有文件添加下划线并重命名它。这就是我对代码的了解。但是它无法重命名文件并给我一个警告,我不确定错误在哪里。
此外,当我在 cmd 行上尝试同一行时,我收到以下错误消息。
$ rename Jacques\ Greene\ -\ Clark\ \(Original\ Mix\).mp3 JG - C.mp3
Bareword "mp3" not allowed while "strict subs" in use at (eval 1) line 1.
$ rename Jacques\ Greene\ -\ Clark\ \(Original\ Mix\) JG - C
Can't locate object method "Original" via package "Mix" (perhaps you forgot to load "Mix"?) at (eval 1) line 1.