in reply to Re: Reading Files/Directories
in thread Reading Files/Directories

This does not work! It's as if the statement is ignored, I still continue to try to process the sub-directories. The files are in a directory off of the root like c:\myfiles. There are subdirectories in this directory that are being picked up as if they are files. I need to skip the subdirectories. -d does not work!

Replies are listed 'Best First'.
Re^3: Reading Files/Directories
by merlyn (Sage) on Apr 04, 2005 at 20:37 UTC
    Did you turn the result of readdir (which is just the name within the selected directory) into a path by reattaching the directory name in front? If not, you're gonna get an odd response.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Thank you, Thank you, Thank you. By referencing the full file path within the condition test, instead of just the name of the file, this works. I was mistakenly under the impression that by being positioned in that directory, on the direcory read, perl would resolve the file as to being a sub-directory or a file. But your method worked fine. Thanks again.
Re^3: Reading Files/Directories
by jZed (Prior) on Apr 04, 2005 at 20:30 UTC
    This works for me:
    #!perl -w use strict; opendir (DIR, './') || die "can't open dir:: $! \n"; for my $file(readdir(DIR)) { next if -d $file; print $file."\n"; }
      Thanks, but the response by Merlyn did the trick.