| Recursively make directories in perl |
I just whipped up the following function to recursively make directories in perl (much like mkdir -p), and thought I might need it again, so here it is:
sub rmkdir{
my($tpath) = @_;
my($dir, $accum);
foreach $dir (split(/\//, $tpath)){
$accum = "$accum$dir/";
if($dir ne ""){
if(! -d "$accum"){
mkdir $accum;
}
}
}
}
[tags: perl mkdir recursive]
posted at: 15:16 | path: /diary | permanent link to this entry
-
#1
Jeremy
Readable Perl? Has the world gone topsy-turvy?!
http://ozlabs.org/~jk/diary/tech/software/pmkdir.diary/
:)
jk
-
#2
Hermann
use File::Copy::Recursive;
File::Copy::Recursive::pathkm( 'path' );
-
#3
Michael Still
I love the Internet. I was literally looking at the recursive mkdir code above while finishing off a script when your comment came along.It saved me 10 lines of code, which was nice.
One thing though -- http://search.cpan.org/~dmuey/File-Copy-Recursive-0.16/Recursive.pm#pathmk() tells me that you've made a typo. It should be File::Copy::Recursive::pathmk
Thanks again...
