in reply to read files one by one in directory and redirct output to a file
You've commented out a bunch of code, why? It's unclear what problem you're having, and unclear how which code is relevant to the question. Please take the time to read and follow How do I post a question effectively? and SSCCE - if you follow that advice, we will be able to provide help much more efficiently.
Just a guess, but perhaps readdir is returning directories as well as just files? And as huck pointed out, the filenames returned by readdir don't include the directory name. Here, I'm using catfile from File::Spec to prefix the directory name to the filename, no_upwards from the same module to filter directory entries like . (curdir) and .. (parent dir), and -f to filter out only files. The sort is optional.
use File::Spec::Functions qw/no_upwards catfile/; opendir my $dh, $dirname or die "$dirname: $!"; my @files = grep {-f} map {catfile $dirname, $_} sort +no_upwards readdir $dh; closedir $dh;
Update: Fixed: "sort no_upwards" was not correct, but the -f test was hiding the issue.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: read files one by one in directory and redirct output to a file
by TonyNY (Beadle) on Jul 06, 2018 at 12:29 UTC | |
by haukex (Archbishop) on Jul 06, 2018 at 12:46 UTC | |
by Marshall (Canon) on Jul 08, 2018 at 01:00 UTC |