in reply to Reading Files/Directories

next if -d $file

Replies are listed 'Best First'.
Re^2: Reading Files/Directories
by GThorne (Initiate) on Apr 04, 2005 at 20:25 UTC
    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!
      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.
      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.