Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How do I recursively create a directory tree/filesystem?

by lemming (Priest)
on Jul 22, 2002 at 18:09 UTC ( #184161=note: print w/replies, xml ) Need Help??


in reply to How do I recursively create a directory tree/filesystem?

For the recursive mkpath solution: Of course reading the docs helps.
use strict; use warnings; use File::Path; my $name = shift; my $branch = shift; my $depth = shift; # We really should be checking arguments # Bad things happen if $branch or $depth is 0 print "Creating directory ",$name," with ", $branch, " branches to the depth of ", $depth, "\n"; my $aref = MkTree($name, $branch, $depth, [] ); foreach my $path ( @$aref ) { print $path, "\n"; } mkpath($aref, 1, 0777); exit; sub MkTree { my ($name, $branch, $depth, $aref) = @_; my $start = "a"; foreach my $pos (1..$branch) { my $let = chr(ord($start) + $pos - 1); if ( $depth == 1 ) { push(@$aref, join('/', $name, $let) ); } else { MkTree( join('/', $name, $let), $branch, $depth-1, $aref); } } return $aref; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2021-09-19 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?