http://www.perlmonks.org?node_id=9576

jrsmith has asked for the wisdom of the Perl Monks concerning the following question:

i have another problem.. i am using -d to test whether it is a directory or not but it is telling me that all my directories are not directories. the only directories it will recognize as directories are NOT directories, and these are the . and .. used to navigate to previous dirs in win32. this is what i get when i run the script:
. is a directory. .. is a directory. Cannot determine filetype of digsol.
here is the filetest section of my script:
if (-f $i) {   print OUTPUT "$i is a file.\n"; } elsif (-d $i) {   print OUTPUT "$i is a directory.\n"; } else {   print OUTPUT "Cannot determine what $i is.\n"; }
are there any known problems with -d and win32? i have looked around here and other sites and haven't seen any similar problems, maybe i'm just doing something wrong? TIA for any insight you can provide
JR

Replies are listed 'Best First'.
Re: another directory question
by jrsmith (Pilgrim) on Apr 28, 2000 at 17:39 UTC
    nevermind i found out what is wrong... -d was testing just the directory name specified by $i when i should have included the path in that like e:/$i or $path$i. thanx anyway :)
      Depeding on how long you intend to spend doing stuff in each directory, it might be a good idea to do a chdir into that directory. This would avoid running into problems like the one you just had.

      This is one of those philosofical issues, like what's best:
      • relative links
      • absolute urls
      Each person has a particular way of doing things, but I just tend to think its a matter of what makes things clearer. In your case, it could be:
      if (-f "$path/$leaf") { } # or simply chdir($path) || warn(); if (-d $leaf) { }
      cheers!