3
我想(通過使用File :: Find)首先列出當前目錄中的所有文件,然後跳轉到子目錄。可能嗎?Perl File :: Find:首先列出目錄中的所有文件,然後跳轉到下一個目錄?
我想(通過使用File :: Find)首先列出當前目錄中的所有文件,然後跳轉到子目錄。可能嗎?Perl File :: Find:首先列出目錄中的所有文件,然後跳轉到下一個目錄?
使用預處理選項下降到子目錄之前,做在每個目錄下的文件:
use strict;
use warnings;
use File::Find 'find';
find(
{
'wanted' => sub { print "$File::Find::name\n" },
'preprocess' => sub { sort { -d $a <=> -d $b } @_ }
},
'.'
);
雖然以避免額外的統計數據,它應該是:
sub { map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -d $_ ], @_ }
有輸入目錄時調用的preprocess回調。它可以用於這樣的任務:
use File::Find;
my $directory = '.';
find({
wanted => sub {
# do nothing
},
preprocess => sub {
print "$File::Find::dir :\n", join("\n", <*>),"\n\n";
return @_; # no filtering
},
}, $directory);
它打印當前目錄名稱和其中的文件列表。請注意,preprocess
被給予用於過濾的所有目錄條目,並且它們需要被返回。
完美!非常感謝你! :) – marverix 2011-04-18 10:35:34