Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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;

Replies are listed 'Best First'.
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 taking refuge in the Monastery: (7)
As of 2016-06-26 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (327 votes). Check out past polls.