【发布时间】:2013-03-27 04:34:58
【问题描述】:
我尝试在循环中使用此条件(-d $var) 来检查给定目录中有多少子目录,但某些文件夹被检测为文件。无法识别目录的情况发生了什么?我该如何解决这个问题?
我的代码是:
foreach my $file (@files) {
next if($file =~ m/^\./);
if (-d $file and -e $file and !$seen{$file}) {
$seen{$file} = 1;
push @Dir, "$pwd/$file";
}
next if ($file !~ m/\s/i);
my $new_name = s/\s//g;
`mv $pwd/$file $pwd/$new_name`;
}
【问题讨论】:
-
这些符号链接是指向目录而不是实际目录吗?
-
不,它是一个实际的目录。 :(
-
整洁。什么类型的文件系统?你能给我们看看代码吗?
-
foreach 我的 $file (@files) { next if($file =~ m/^\./); if (-d $file and -e $file and !$seen{$file}) { $seen{$file} = 1;推@Dir, "$pwd/$file"; } 下一个 if ($file !~ m/\s/i);我的 $new_name = s/\s//g;
mv $pwd/$file $pwd/$new_name; } -
@files数组的内容是什么?是来自glob电话还是readdir电话?
标签: linux perl file unix directory