Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by lemming (Priest)
on Jul 22, 2002 at 18:09 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found