Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Override CORE::mkdir

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

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




=head1 NAME - override CORE::mkdir with "complete" version.


    use strict;
    use warnings;
    use Mkdir;

Replies are listed 'Best First'.
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);


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2016-10-25 03:09 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (313 votes). Check out past polls.