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.