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

I am attempting to move a bunch of jpeg files into a different directory while renaming them in order. I am on windows xp and when I run the script I get Permission denied at line 13, where I attempt to copy/rename the file.

The directory, "trip" that is created is marked as "read only" when I view folder properties. Even when I remove the read only attribute from the directory it reverts back. (Perhaps this is a windows problem)

Any ideas?
#!/usr/bin/perl use strict; mkdir "trip", 077; my $count = 1; for (1..4) { opendir(DIR,"trip" . $_); my @files = sort readdir DIR; for ( @files ) { rename ($_, "./trip/" . $count ) || die $!; $count++; } }

Replies are listed 'Best First'.
Re: directory access failure
by davido (Cardinal) on Jul 20, 2004 at 15:50 UTC
    You created a directory named "trip", and then you attempt to open directories named "trip1", "trip2", "trip3", and "trip4". Those directories don't exist.

    Dave

      Thanks davido, you helped me find the problem. Lets just say it's been a while since I've done any coding =)
Re: directory access failure
by trantor (Chaplain) on Jul 20, 2004 at 15:17 UTC

    The problem is that you're creating directories with:

    mkdir "trip", 077;

    You most likely wanted 0777, or you can omit the mask parameter completely and Perl will do the right thing for you :-)

    Moreover, a quick inspection of @files revealed the other possible problem: the special directories . and .. are included in the array, and your script is trying to rename them as well. I couldn't test it on Windows (using Linux here) but it should be the same.

    Update: mentioned that @files contains . and ..

      You're right, I did mean to type 0777, however even without the mask I get the error.