可能重复: Renaming and Moving Files in Bash or Perl如何检查文件是否存在,并在Perl重命名
我有点新手,Perl和寻找一个脚本,将处理的文件移动。
#!/usr/bin/perl -w
$filename = 'DUMBFILE';
$destination = '/some/location/';
if (-e $destination + $filename) {
print "File Exists ! Renaming ..";
move ('/tmp/' + $filename, $destination + $filename + '.1');
} else {
move ('/tmp/' + $filename, $destination + $filename);
}
我能够将其重命名为1,但我不想被逐步改名,就像如果file.1的存在,重命名为.2和.3如果0.2存在。
编辑:并保持扩展相同;喜欢的file.exe变得file.exe.1,file.exe.2等
字符串连接使用'.'不'+'来实现的。您最好使用'Path :: Class'或'File :: Spec'来形成单个组件的路径。最后,你的脚本的逻辑不清楚。你似乎用'/ tmp/DUMBFILE'来覆盖'/ some/location/DUMBFILE.1'。 – 2010-03-31 14:13:46
这是http://stackoverflow.com/questions/2548835/renaming-and-moving-files-in-bash-or-perl/2548919#2548919的副本。 (在主题中忽略“bash” - OP说perl很好) - 接受的答案提供了移动脚本 – DVK 2010-03-31 17:07:18