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

I'm writing a script, which will be used to check and update a number of files/directories on a remote NT machine. It needs to be able to anticipate the possibility that a completely new set of sub directories may need to be created. The problem is that mkdir only appears to work if the directory above the one I wish to make exists.
E.g.
mkdir ("c:/test/test2/test3") works if c:/test/test2/ exists. However, if the sub directory "test2/" does not exist, then it fails.
Is there a way to get around this, without having to check that all the sub directories are present and if necessary make them one by one???
Many thanks...

Replies are listed 'Best First'.
(jeffa) Re: Problems with mkdir
by jeffa (Bishop) on Dec 08, 2001 at 23:06 UTC
    Try File::Path:
    use File::Path; mkpath('foo/bar/baz/qux') or die;

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)
    
      Thanks!