Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Problems with -d filetest on readdir results

by cjf (Parson)
on May 23, 2002 at 19:07 UTC ( #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? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2022-05-24 19:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?