in reply to Perl API that emulates mkdir -p on unix?

Here is somthing I wrote to do what you need.

#Note this is windows centric use strict; make_dir("c\:\\this\\is\\a\\deep\\subdirectory\\"); sub make_dir { my ($inpath) = @_; #Full directory path my $path = ""; #Storage path #Loop through the sections foreach(split/\\/,$inpath) { #Add to path $path .= $_ . "\\"; #Elimnate the drive and check to see if path exists if(!/\:/ and !-e $path) { #If not then make it mkdir $path; #Show status for demo print "Makeing $path\n"; } } }

Replies are listed 'Best First'.
Re^2: Perl API that emulates mkdir -p on unix?
by Anonymous Monk on Jun 20, 2012 at 18:23 UTC
    Just emulate the Linux function:
    sub MkDirs ($) { my ($Dir) = @_; my @Folders = split(/\\|\//, $Dir); $Dir = shift @Folders; foreach my $Folder (@Folders) { $Dir = File::Spec->catfile( $Dir, $Folder ); mkdir $Dir unless (-e $Dir); } }
      the easiest way with native Perl
      sub mkdirp($) { my $dir = shift; return if (-d $dir); mkdirp(dirname($dir)); mkdir $dir; }