Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Override CORE::mkdir

by larryk (Friar)
on Feb 18, 2002 at 21:44 UTC ( #146259=snippet: print w/ replies, xml ) Need Help??

Description:

Having read the discussion at recursive mkdir I decided to post this. I don't know who wrote it - it may have been me as it looks like code I could have written but I don't recall :-S

It exports mkdir which will create all nonexistent directories in the path provided.

package Mkdir;

use base qw(Exporter);
use strict;
use subs 'mkdir';
use warnings;

our @EXPORT = qw(mkdir);

sub mkdir {
    my $path = shift;
    my $mode = shift || '0777';
    my $d = '';
    for (split/[\\\/]/,$path) {
        $d .= $_.'/';
        -d $d || CORE::mkdir($d,$mode) || return
    }
    1;
}

1;

__END__

=pod

=head1 NAME

Mkdir.pm - override CORE::mkdir with "complete" version.

=head1 SYNOPSIS

    #!perl
    
    use strict;
    use warnings;
    
    use Mkdir;
    
    mkdir('/create/all/of/these/directories/',0755);

=cut
Comment on Override CORE::mkdir
Download Code
Re: Override CORE::mkdir
by Kanji (Parson) on Feb 18, 2002 at 21:54 UTC

    You might want to check out File::Path's mkpath function, which provides similar functionality and has the added bonus of being a core module ... so nothing extra to install. :)

    # The "mkpath" function provides a convenient way to create # directories, even if your "mkdir" kernel call won't create # more than one level of directory at a time. mkpath(['/create/all/of/these', '/and/these/too'], 0, 0755);

        --k.


Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2015-07-07 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls