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' );


    Add a comment to this post:

    Your name:

    Your email: Email me new comments on this post
      (Your email will not be published on this site, and will only be used to contact you directly with a reply to your comment if needed. Oh, and we'll use it to send you new comments on this post it you selected that checkbox.)


    Your website:

    Comments: