Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Searching directories

by LazerRed (Pilgrim)
on Sep 23, 2003 at 01:48 UTC ( #293358=note: print w/ replies, xml ) Need Help??


in reply to Searching directories

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.


Comment on Re: Searching directories
Select or Download Code
Re:Searching directories
by pen (Acolyte) on Sep 23, 2003 at 13:32 UTC
    This is allot of help LazerRed:)
    I was wondering if this could be what it was, and was looking at ways of biulding the path but just couldn't get it right at all. Still allot to learn at this point.

    As for the other two suggestions thanks but I think they are a little ahead of me at this point. I will keep them in mind and come back to it at some point.

    I now have what I want but instead of using openDir I am now using glob. Is this a good way to go for a recursive sub?

    Thanks again
    Paul Neale

      Is this a good way to go for a recursive sub?
      Generally accepted answer: no. Use File::Find, which is a standard module, or maybe File::Find::Rule, which many people seem to prefer — I don't know it personally, but I thought I'd mention it anyway, otherwise there is bound to be a follow-up to this post pointing to it. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://293358]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-09-15 05:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (145 votes), past polls