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

Hi, I am trying to create a directory "work\\startup" if it doesnt exist using the following code,it fails to create the directory?Appreciate any inputs?

my $cmdls = system("ls work\\startup"); if ($cmdls != 0) { print "create work\\startup directory\n"; my $cmdmkdir = system("mkdir work\\startup"); if ($cmdmkdir != 0) { print("create work\\startup directory failed\n"); exit 1; } }

Replies are listed 'Best First'.
Re: Failed to create work\\startup directory
by toolic (Bishop) on Apr 24, 2011 at 23:04 UTC
Re: Failed to create work\\startup directory
by jwkrahn (Abbot) on Apr 24, 2011 at 23:05 UTC
    if ( -d 'work' && ! -e 'startup' ) { print "create work/startup directory\n"; mkdir 'work/startup' or do { print "create work/startup directory failed because :$!\n"; exit 1; }; }

      The thing is directory "work" also needs to be created first and then work/startup.Is the below "if condition" right to check if a directory "work" already exists?

      if ( ! -e 'work' )#Is this condition right? { print "creating work/startup directory\n"; mkdir 'work' or do { print "create install directory failed because :$!\n"; exit 1; }; mkdir 'work/startup' or do { print "create work/startup directory failed because :$!\n"; exit 1; }; }
Re: Failed to create work\\startup directory
by wind (Priest) on Apr 24, 2011 at 23:43 UTC

    Use mkdir

    for (qw(work work\startup)) { mkdir or -e or die "mkdir $_: $!"; }

      Getting the following error

      Not enough arguments for mkdir at perl.pl line 27, near "mkdir or" Execution of perl.pl aborted due to compilation errors.

        Do you have the for loop like I have it?

        If so, what's the exact error that you get?