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

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

by gube (Parson)
on Mar 09, 2006 at 07:48 UTC ( #535343=note: print w/ replies, xml ) Need Help??


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

Hi try this,

use File::Find; find(\&file_names, "/home/gube/"); sub file_names { print "$File::Find::name\n" if(-f $File::Find::name); }
Update : If you want to find only the directories use this code:
use File::Find; find(\&dir_names, "/home/gube/"); sub dir_names { print "$File::Find::dir\n" if(-f $File::Find::dir,'/'); }
Regards, Gube.


Comment on Re: how to get the all the subdirectories path from the directory
Select or Download Code
Re^2: how to get the all the subdirectories path from the directory
by mickeyn (Priest) on Mar 09, 2006 at 08:35 UTC
    I agree with Gube about using File::Find.
    But you don't need to bother writing the code, just use find2perl:

    find2perl . -type d

    will generate the code for you:

    you can use 'find2perl' to convert 'find' syntax to perl code.

    Enjoy,
    Mickey

Re^2: how to get the all the subdirectories path from the directory
by radiantmatrix (Parson) on Mar 09, 2006 at 16:27 UTC

    I don't think those do what you think they do. Here are some options:

    use File::Find; #print all entries at or below starting dir: find ( sub { print $File::Find::name,"\n" }, '.' ); #print all directories at or below starting dir: find ( sub { next unless -d; print $File::Find::name,"\n"; }, '.' ); #print all entries, trailing directories with a '/': find ( sub { print $File::Find::name,(-d $_ ? '/' : ''),"\n" },'.' );
    <-radiant.matrix->
    A collection of thoughts and links from the minds of geeks
    The Code that can be seen is not the true Code
    I haven't found a problem yet that can't be solved by a well-placed trebuchet

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-08-23 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls