我在一个文本文件上使用 File::Find 和 file i/o 来解析一系列目录并将内容移动到一个新文件夹中。这是一个简单的脚本(见下文):
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use File::Copy;
my $dir = "/opt/CollectMinderDocuments/coastalalglive"; #base directory for Coastal documents
#read file that contains a list of closed IDs
open(MYDATA, "Closed.txt");
mkdir("Closed");
while(my $line = <MYDATA>) {
chomp $line;
my $str = "$dir" . "/Account$line";
print "$str\n";
find(\&move_documents, $str);
}
sub move_documents {
my $smallStr = substr $File::Find::name, 43;
if(-d) {
#system("mkdir ~/Desktop/Closed/$smallStr");
print "I'm here\n";
system("mkdir /opt/CollectMinderDocuments/coastalalglive/Closed/$smallStr");
#print "Made a directory: /opt/CollectMinderDocuments/coastalalglive/Closed/$smallStr\n";
}
else {
print "Now I'm here\n";
my $smallerStr = substr $File::Find::dir, 43;
my $temp = "mv * /opt/CollectMinderDocuments/coastalalglive/Closed/$smallerStr/";
system("$temp");
}
}
文本文件包含一个数字列表:
1234
2805
5467
该代码在我上个月执行时有效,但现在返回“找不到文件或目录”错误。实际错误是"No such file or directoryerDocuments/coastallglive/Account2805"。我知道它正在搜索的所有目录都存在。我手动输入了其中一个目录,脚本执行得很好:
find(\&move_documents, "/opt/CollectMinderDocuments/coastalalglive/Account2805/");
我不确定为什么返回错误。在此先感谢您的帮助。