I have what I believe is one of the simplest of question but am having a lot of trouble figuring out what is going on. Here is the issue:

I am running on Windows XP and am trying to do a simple directory traversal task. I have done this many, many times on Unix systems but have, surprising to myself, never done it on a Windows XP system.

I do a simple file test, of the form:

if( -d $entry ) {do something}else{do something else}

The problem is that this never identifies anything as a directory (i.e., only the "do something else" clause gets executed.

I know that when it comes to Win32 systems there are some special considerations, especially regarding the file & directory handling strategies, but this one puzzles me.

I have searched on the web for Perl and Window XP and have seen a lot of special considerations and have looked to resources such as the "Learning Perl on Win32...." But I can't find anything that says why (or even that) this doesn't work.

I'm not interested in wasting anyone's time; this is not worthy of any such effort. I'm just looking for a nudge or two about where I might look for more information on unique issues/considerations on using Perl on Win32 systems.

Also, I know that there are plenty of Modules out on CPAN that will solve the problem; I'm just looking to understand "what's under the hood" so to speak on Perl and Win32 on file test operations.

This issue really tripped me up. It leaves me feeling really stupid (probably for good reason); but I really like to understand what's going on so that I can better handle these things for myself in the future...and to better appreciate all that the CPAN modules bring to my efforts.

UPDATE: Thanks to everyone. Seems like the general consensus is that I'm not in the directory that I think I'm in.

Also, most everyone suggested that I post some of the code so that it could be clearer what I'm experiencing. I shoud have done that when I posted (my bad); I appologize for not doing so.

I thought the problem would be so easy to spot that the rest of the code would just clutter up the posting. But I see that my reasoning was incorrect.

I have provided the code below...it's not too long.

What I'm trying to do is to get a count of all the pictures I have in a particular directory (which I specify in the $top_directory variable...I set it to a full path name). I go to that directory, read in all its contents and then one-by-one check to see if the entry is a directory (which I would then traverse in recursive style, depth-first.

It is that directory check that is giving me trouble.

Here is the code. I have abbreviated it to focus on what I believe is the essential infomration.

UPDATE 2:

Sorry, I should have noted that the code below is extracted from my picture counting code. I have deleted all of the log file handling and specific counting steps. I have reduced the code to the essence of what is failing. In the below-provided code, I simply try to print out a statement indicating when I find a directory entry in the top directory. Even though there are sub-directories in this top directory, none ever gets put into the printout.

Here is the code...

#!/usr/bin/perl use strict; use warnings; my $top_dir = "C:/Documents and Settings/Owner/My Documents/My Picture +s"; $top_dir = $top_dir . "/ACK_Kenya_2008/"; opendir(THISDIR,$top_dir) || die "$0: Can't open directory '$top_dir': $!\n"; my @file_list = readdir(THISDIR); # slurp in all directory entries closedir(THISDIR) || die "$0: Can't closer current directory '.': $!\n"; my $tot_count = 0; my $line = " PICTURES\n"; foreach my $this_file (@file_list) { next if($this_file =~ /^\.{1,2}$/); # ignore the . and .. entries my $file = $top_dir . $this_file; # be sure to use file with full + path name if(-d $file) { print "$this_file is a directory\n"; } # end if } # end foreach $file loop exit(0);
ack Albuquerque, NM

In reply to Directory checking on Windows XP by ack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.