我从http://www.perlmonks.org/index.pl?node_id=217166转换的Linux脚本明确这一点:为什么我不能在Perl中删除这个空目录?
#!/usr/bin/perl -w
use strict;
use Getopt::Std;
use File::Find;
@ARGV > 0 and getopts('a:', \my %opt) or die << "USAGE";
# Deletes any old files from the directory tree(s) given and
# removes empty directories en passant.
usage: $0 [-a maxage] directory [directory ...]
-a maximum age in days, default is 120
USAGE
my $max_age_days = $opt{a} || 120;
find({
wanted => sub { unlink if -f $_ and -M _ > $max_age_days },
postprocess => sub { rmdir $File::Find::dir },
}, @ARGV);
我的尝试是:
#!/usr/bin/perl -w
use strict;
use Getopt::Std;
use File::Find;
@ARGV > 0 and getopts('a:', \my %opt) or die << "USAGE";
# Deletes any old files from the directory tree(s) given and
# removes empty directories en passant.
usage: $0 [-a maxage] directory [directory ...]
-a maximum age in days, default is 120
USAGE
my $max_age_days = $opt{a} || 120;
find({
wanted => sub { unlink if -f $_ and -M _ > $max_age_days },
# postprocess => sub { rmdir $File::Find::dir },
postprocess => sub {
my $expr = "$File::Find::dir";
$expr =~ s/\//\\/g; # replace/with \
print "rmdir $expr\n";
`rmdir $expr`;
},
}, @ARGV);
但是我得到当脚本试图删除目录说,目录是一个错误由另一个进程使用(当不是时)。有任何想法吗?我正在使用ActiveState 5.10在Windows Server 2003 SP2 64位上运行脚本。
谢谢!
要补充的是:这里的问题是,在Linux上可以删除文件和在Windows中不能使用的目录。这就是为什么它没有修改就无法正常工作。 – 2008-12-08 17:07:57