Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Problems with -d filetest on readdir results

by cjf (Parson)
on May 23, 2002 at 19:07 UTC ( [id://168880]=note: print w/replies, xml ) Need Help??


in reply to Problems with -filetest on readdir results

You need to provide -d with the $path ...

#!/usr/bin/perl -w use strict; my $path = "/usr/bin"; opendir DIR, $path or die "Couldn't read directory: $!"; my @directories = grep { -d "$path/$_" } readdir DIR; closedir DIR; foreach (@directories) { print $_, "\n"; }

Update: Changed $path to "$path/$_" so it prints out only the directories (as opposed to all the files). Thanks to ChemBoy for spotting this and providing the fix.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found