我不想解析我的一些子目录。为此,我可以在下面的这些功能中修改哪些内容。
use File::Find;
find(\&wanted, @directories_to_search);
sub wanted { ... }
这是我的目录树:
LOG
├── a.txt
├── b.txt
└── sdlog
├── 1log
│ ├── a.txt
│ └── b.txt
└── 2log
├── a.txt
└── b.txt
|__abcd
|__efgh
我想解析 sdlogs 和 1log 。除了这些子目录,我不想解析任何其他子目录。
答案 0 :(得分:1)
您不希望File::Find
在这里。
use warnings;
use strict;
# you probably want to use the abs. path
my $dir = "testdir";
opendir(my $dh, $dir);
# grep out directory files from the list of files to work on
# this will also skip "." and "..", obviously :)
my @files = grep { ! -d } readdir $dh;
closedir $dh;
# change to the given directory, as readdir doesn't return the relative path
# to @files. If you don't want to chdir, you can prepend the $dir to $file as
# you operate on the $file
chdir $dir;
for my $file (@files) {
# do stuff..
# E.g., "open my $fh, ">>", $file;", etc
print $file, "\n";
}
输出
$ ./test.pl
a_file.txt
b_file.txt
c_file.txt