Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by Codmate (Novice)
on Mar 12, 2003 at 18:09 UTC ( #242450=categorized answer: print w/replies, xml ) Need Help??

Q&A > directories > How do I find directories within directories using : parse_dir(`ls -l`) - Answer 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?
[Discipulus]: uch; everytime i want to read some source code i finally choke against an XS..

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2016-12-05 10:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (78 votes). Check out past polls.