Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: how to get the all the subdirectories path from the directory

by leocharre (Priest)
on Mar 09, 2006 at 16:06 UTC ( #535420=note: print w/ replies, xml ) Need Help??


in reply to how to get the all the subdirectories path from the directory

If you're running this on a linux box, you could use backticks.

my @dirs = split(/\n/,`find /from/this/place/on -type d`);

Nice thing about this is that you are using linux find, you can specify a lot of options, like formatting the output to get inode, timestamp, you can sort them by date, whatever.

You may want to do a man find from your shell prompt- it would show you the options.

You have to be aware that using backticks is more of a temporary script thing, for throw-away code. There are security and i guess portability issues with backticks.


Comment on Re: how to get the all the subdirectories path from the directory
Select or Download Code
Replies are listed 'Best First'.
Re^2: how to get the all the subdirectories path from the directory
by graff (Chancellor) on Mar 09, 2006 at 23:27 UTC
    Not just linux, of course; any unix (sunos, bsd, macosx, ...) -- and of course a few different ports of unix tools (including a fully function "find" utility) ported to all versions of ms-windows/dos (gnu/cygwin, att research labs, ...)

    As for security concerns, you can do:

    open( $fh, "-|", "find", "/start/path", "-type", "d" ); while (<$fh>) { ... }
    That's as portable as perl 5.8.x and the command-line "find" util (i.e., runs anywhere). I actually prefer using this approach over File::Find and its derivatives, because the perl modules tend to go a lot slower on really big directory trees, whereas the compiled "find" util is as fast as you can get.
      We can use the @all_files = `find . -depth` ; // From the current directory @all_files = `find /path/ -depth` ; // To get all the paths from the path . Regards, Sravan
Re^2: how to get the all the subdirectories path from the directory
by Anonymous Monk on Mar 19, 2015 at 21:05 UTC
    Excellent solution, it worked for me thanks for the tip!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2015-07-08 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls