in reply to Determine if object is file or directory?

print "nothing\n" if not -e $filename; print "directory\n" if -d $filename; print "file\n" if -f $filename;
perlfunc - see the -X pseudo-functions.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re: Re: Determine if object is file or directory?
by ysth (Canon) on Apr 08, 2004 at 07:25 UTC
    Remember to prepend the directory to the filename:
    opendir D, "pbed" or die; while (my $file = readdir D) { if (-d "pbed/$file") { print "dir: $file\n"; } else { print "file: $file\n"; } }
      Or skip the ugly readdir() dance altogether. It's amazing how many people like going around their elbow to get to their thumb. Use glob() or the angle brackets, that's why they are there.
      @files = grep { not -d } <$path/*>;

      --
      [ e d @ h a l l e y . c c ]