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

Dear Monks,
I'm trying to create a directory on Windows 98 doing either one of these three things:
mkdir $mydir, 0755
mkdir $mydir
my $cmd=`mkdir C:\Windows\Temp\myfolder`
On the first two, I got the error "Permission denied". On the 3rd one, the error was "Unable to create directory".

Please help!
Thank you!!!

Replies are listed 'Best First'.
Re: mkdir on Windows 98
by ccn (Vicar) on Aug 16, 2004 at 17:24 UTC
Re: mkdir on Windows 98
by bobf (Monsignor) on Aug 17, 2004 at 02:56 UTC

    You might want to look at File::Spec, File::Path, and File::Copy. File::Spec is great for performing portable directory and filename operations (you don't have to remember which way the slashes should go). File::Path makes it very easy to create directory trees without having to specifically create all of the intermediate directories. File::Copy is used to copy or move files. As with any function call, you should verify it worked by either performing an independent test or by checking the return value.

    For example:
    use strict; use warnings; use File::Path; use File::Copy; use File::Spec; # Assemble a new dir name and create it my $dirpath = File::Spec->catdir( 'C:', 'dir1', 'dir2' ); mkpath( $dirpath ); # make sure the dir we tried to create exists, using -d (one option) my $install_error = 0; unless( -d $dirpath ) { $install_error = 1; } # (stuff if mkpath failed) my $pathfile = File::Spec->catfile( $dirpath, 'myfile.txt' ); my $copy_status = copy( 'myfile.txt', $pathfile ); if( $copy_status == 1 ) { print " copied myfile.txt to $dirpath\n"; } else { print " *** Error copying file: $!\n"; }
    HTH
Re: mkdir on Windows 98
by ikegami (Patriarch) on Aug 16, 2004 at 17:24 UTC
    If you're trying to create C:\Windows\Temp\myfolder, does C:\Windows\Temp exist? It must, unless you're using File::Path's mkpath or similar.
Re: mkdir on Windows 98
by Random_Walk (Prior) on Aug 16, 2004 at 17:27 UTC
    Just a couple of quick ideas.

    Can you create this directory yourself from the command line ?

    On the first two is your code running in the directory where you have permission to make a dir ?

    Try running the third but with escaped forwards slashes, ie:

    `mkdir C:\\Windows\\Temp\\myfolder`;
    Cheers.
      Dear ikegami, ccn and Random_Walk,
      Thank you very much for helping me. I tried these three things and they all worked:

      `mkdir C:\\Windows\\Temp\\myfolder`;

      my $folder="C:\\Windows\\Temp\\myfolder";
      my $cmd=`mkdir $folder`;

      my $folder="C:\\Windows\\Temp\\myfolder2";
      mkdir "$folder", 0755 or warn "Cannot make directory: $!\n";

      I really appreciate your help! I guess I got myself confused by the slashes!
      Best regards,
      shn4002
Re: mkdir on Windows 98
by Kyoichi (Novice) on Aug 16, 2004 at 22:29 UTC
    You can always use 'md' that is an alias in windows to 'mkdir' using:
    my $dirname = 'c:/path/to/newdir'; system( 'md', $dirname );

    Greetings
    -- Kyoichi
      Thanks Kyoichi! I'll try that as well!