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.

have @ opendir , readdir.

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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -