Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Answer: How do I find directories within directories using : parse_dir(`ls -l`)

( #242450=categorized answer: print w/ replies, xml ) Need Help??

Q&A > directories > How do I find directories within directories using : parse_dir(`ls -l`) contributed by Codmate

You could hand-roll it as follows.

Use ls to get a list of directories...

chomp (my @dir = `ls $path`);
...and then test each entry to see whether it is a directory:
my @list_of_directories = grep { -d "$path/$this_entry" } @dir;

Comment on Answer: How do I find directories within directories using : parse_dir(`ls -l`)
Select or Download Code
Re: Answer: How do I find directories within directories using : parse_dir(`ls -l`)
by jasonk (Parson) on Mar 12, 2003 at 18:18 UTC

    This is far from the "best" way. A much shorter (and less resource intensive, and more portable) method is:

    my @list_of_direcories = grep(-d, <$path/*>);

    We're not surrounded, we're in a target-rich environment!
      ...but the original poster said they had to use "ls".
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-11-27 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (180 votes), past polls