perl - How does File::Find module work? -
i don't want parse of subdirectories. that, things can modify in these function below.
use file::find; find(\&wanted, @directories_to_search); sub wanted { ... }
here directory tree:
log ├── a.txt ├── b.txt └── sdlog ├── 1log │ ├── a.txt │ └── b.txt └── 2log ├── a.txt └── b.txt |__abcd |__efgh
i want parse sdlogs , 1log. apart these subdirectories, don't want parse other.
you don't want file::find
here.
use warnings; use strict; # want use abs. path $dir = "testdir"; opendir(my $dh, $dir); # grep out directory files list of files work on # skip "." , "..", :) @files = grep { ! -d } readdir $dh; closedir $dh; # change given directory, readdir doesn't return relative path # @files. if don't want chdir, can prepend $dir $file # operate on $file chdir $dir; $file (@files) { # stuff.. # e.g., "open $fh, ">>", $file;", etc print $file, "\n"; }
output
$ ./test.pl a_file.txt b_file.txt c_file.txt
Comments
Post a Comment