snowlight has asked for the wisdom of the Perl Monks concerning the following question:
I am using Strawberry perl on Win7 (64-bit) and have an issue with read_dir. The simple code:
use strict; use warnings; use File::Slurp; my @files; # Array of all file names in the folder. if($ARGV[0]) { @files = read_dir($ARGV[0]); } else { @files = read_dir("."); } for my $file (@files) { print $file; if(-f $file) { print " is a file.\n"; } else { print " is a dir.\n"; } }
The file structure used for test:
file1.txt filetest.pl folder -> file2.txt file3.txt
Running this on current (working) dir, gives correct output:
file1.txt is a file. filetest.pl is a file. folder is a dir.
but when providing folder as argument, the files in it are not recognized as files:
What am I missing?file2.txt is a dir. file3.txt is a dir.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: read_dir issue
by moritz (Cardinal) on Aug 24, 2013 at 19:16 UTC | |
Re: read_dir issue
by fishmonger (Chaplain) on Aug 24, 2013 at 20:39 UTC | |
Re: read_dir issue
by zork42 (Monk) on Aug 26, 2013 at 07:59 UTC |
Back to
Seekers of Perl Wisdom