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

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

        --k.