I do not have a D: on this win box, but maybe modification will help you see what is going on. I run my version from C:/ and get the desired results.

my $dirs2 = "C:/WINNT"; opendir $dirs2, "C:/WINNT" or die "Could not open directory: $!"; while ($_ = (readdir $dirs2)) { if (-d "$dirs2/".$_) { print "Directory: $_\n"; } }

What's happining with your script is:

You are reading the contents of D: while running the script from C:
Your list of files are created, then you want to check if they are directories. Your directory check is being performed with a C: path from the files read in from D: because "readdir" does not include the absolute pathname of a file. So, unless you have a directory on D: that is the exact same as what is on C: nothing will be printed.

Hope this helps.

LR

Update: For clarity, you need to provide a fully qualified path to your directory check, because perl will default to the current directory it was run from if you do not. (or use a cwd)

Whip me, Beat me, Make me use Y-ModemG.

In reply to Re: Searching directories by LazerRed
in thread Searching directories by pen

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.