in reply to Re: make_path for creating directory tree
in thread make_path for creating directory tree

Thank you for your answer, good to hear that Perl can handle it :)

Ok so I just tried to use make_path and I did something wrong.

#/bin/perl/ use strict; use warnings; use File::Path qw(make_path); make_path("~/folder1/folder2/folder3/folder4");

This creates the following directories: ~ (!!!), then folder1, then folder2, then folder3 and then folder4. If I use single quotes it just exits quietly without an error but without creating anything either. Any thoughts???

EDIT: Sorry, we posted simultaneously! I'll study your example and retry.

Replies are listed 'Best First'.
Re^3: make_path for creating directory tree
by james28909 (Deacon) on Dec 23, 2015 at 15:37 UTC
    You're on linux? Im booted into windows, but anyway, are you trying to build directories in /home? If so try "/home/folder1/folder2/folder3/folder4" im pretty sure that you would need to use native 'mkdir' command to use '~/'

    EDIT: Use '~/' like this: 'mkdir -p ~/one/two/three'. I do not see any references to File::Path supporting or NOT supporting '~/'. So maybe someone else can chime in about this. :)

      Yes, I'm on Linux. Sorry, this is really embarrassing but I'm still not using the command properly, dear me :( Now I did

      #/bin/perl/ use strict; use warnings; use File::Path qw(make_path); make_path("/one/two");

      In order to test for now, I try to create the path /one/two just in the current directory but I get the error "mkdir /one: Permission denied at test.pl line 8"

      Embarrassing :( What's happening? Do I need to specify the full path to the working directory, and use the command as make_path("/full/path/to/current/directory/one/two")? It's a bit scary as I'm worried this will delete a file accidentally or something catastrophic like that.

        You're trying to create folders in root '/' and dont have proper permission. Try make_path("one/two/three"); or make_path("./one/two/three");

        EDIT: Also, you can test if a dir exists before creating it.
        next if (-d $dir); #will skip to next dir IF target dir exists make_path("one/two/three");