-1
我有一个文件目录我想分割成使用perl子目录由于文件数量。文件名的格式是YYYYMMDD格式的开始日期,我试图在这个文件上进行分割。我使用改编自this StackOverflow Answer下面的代码:我的Perl替换有什么问题?
#!/usr/bin/perl -w
use strict;
opendir DIR, "." or die "opendir: $!";
my @files = readdir(DIR);
closedir DIR;
foreach my $f (@files) {
-f $f or next;
(my $new_name = $f) =~ s!^((....)(..)(..).*)$!$2/$3/$4/$1/;
-e $new_name and die "$new_name already exists";
rename($f, $new_name);
}
不过,我得到一个“换人替代在movefiles.pl线10没有终止”当我尝试运行此代码时。据我所见,我正在逃避并正确终止替换?
与你的问题无关,但你应该检查重命名是否成功。 – 2013-04-25 10:54:57
好点!我也会解决这个问题。谢谢。 – 2013-04-25 11:22:02