in reply to file's treatment
One other point: you could do what you want in a single pass, using "grep":
How easy is that? If you really want to list all the files and non-files to STDOUT while you're reading the directory (which you'll probably get tired of quickly), here's what I would put in place of that single grep line:my $path = "C:/some/path"; opendir( ORIG, $path ) or die "opendir failed on $path: $!"; my @filesInDir = grep { -f "$path/$_" } readdir( ORIG ); closedir ORIG;
Personally, I like the shorter version better.while ( my $file = readdir( ORIG )) { my $verb = "isn't"; if ( -f "$path/$file" ) { push @filesInDir, "$path/$file"; $verb = "is"; } print "$path/$file $verb a file\n"; }
|
|---|