Sprad has asked for the wisdom of the Perl Monks concerning the following question:

The behavior of mkdir on Win32 confuses me. If you try to make a directory within a directory that doesn't exist, mkdir will fail with a "no such file or directory" error. The DOS mkdir, however, makes the directory along with all the ones above it, as you (or at least I) would expect. Is there some trick to it, or does DOS actually have one up on Perl this time?

---
A fair fight is a sign of poor planning.

Replies are listed 'Best First'.
Re: Getting deep with mkdir
by jZed (Prior) on Nov 22, 2003 at 01:05 UTC
    use File::Path;
    mkpath('/some/nonexistant/path');
    

    It's part of the perl core and it will do the right thing for making paths when some or all of the path is non-existant.

Re: Getting deep with mkdir
by mpeppler (Vicar) on Nov 22, 2003 at 01:06 UTC
    This is the expected behavior of the mkdir() function. You can use the mkpath() call from File::Path to create more than one level of directories at a time.

    Michael

Re: Getting deep with mkdir
by ysth (Canon) on Nov 23, 2003 at 02:39 UTC
    Be aware that File::Path::mkpath throws an exception (aka dies) on error, so for normal use you would want to wrap it in an eval and check $@ to see if it succeeded.