-1

我不想解析我的一些子目录。为此,我可以在下面的这些功能中修改哪些内容。

 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

我想解析sdlogs1log。除了这些子目录,我不想解析任何其他子目录。

4

1 回答 1

1

你不想File::Find在这里。

看看opendirreaddir

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
于 2013-08-08T06:14:25.733 回答