iKnowNothing has asked for the wisdom of the Perl Monks concerning the following question:
I'm scratching my head on this one. My windows machine has two versions of perl installed. Version 5.005_02 is the default version used from the command line. (This is a corporate administered machine, so that is why we are on an ancient version).
I also have Matlab installed, which comes bundled with version v5.8.8.I have written a simple script to rename directories (which we need to do quite often to workaround some configuration management issues). The script works fine when using the older version of perl, but when I use v5.8.8, the rename fails with permission denied errors.
Any thoughts on this? I don't see why permission would be denied when using one version of perl over the other. Also, I have no problems renaming these directories manually.
error message:code:Could not rename "D:\data\jhopkin\My Documents\Synergy\ccm_wa\ams_test +\MatlabSynergy2-jhopkin\MatlabSynergy2\3atsym3testdir" to "D:\data\jh +opkin\My Documents\Synergy\ccm_wa\ams_test\MatlabSynergy2-jhopkin\Mat +labSynergy2\@testdir": Permission denied at renameDirs.pl line 43.
if(@ARGV != 3) { displayHelp(); die "Must have three arguments!"; } $from = $ARGV[0]; $to = $ARGV[1]; my $startDir = $ARGV[2]; if(!is_dir($startDir)) { die "$startDir is not a directory!"; } renameRecurse($startDir); sub renameRecurse { my $dirIn = $_[0]; my $file2 = ""; opendir DIR, $dirIn; my @entries = readdir(DIR); close DIR; foreach $file (@entries) { #skip the "." and ".." if($file ne "." && $file ne "..") { if(is_dir("$dirIn\\$file")) { renameRecurse("$dirIn\\$file"); } if(substr($file,0,length($from)) eq $from) { $file2 = $file; $file2 =~ s/$from/$to/; rename "$dirIn\\$file","$dirIn\\$file2" or die "Could +not rename \"$dirIn\\$file\" to \"$dirIn\\$file2\": $!"; } } } } sub is_dir() { if ( -d $_[0] ) { return 1; } else { return 0; } } sub displayHelp { print <<END; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $0 Usage: $0 <from> <to> <startdirectory> Will recursively look through startdirectory for directories beginning with <from>. Will rename directory, replacing <from> with <to>. Example: $0 "@" "3ATSYM3" "C:\\change\\my\\at\\symbols" Created by Jesse Hopkins May 13th, 2010 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~ END }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem using rename
by toolic (Bishop) on Jul 13, 2010 at 15:10 UTC | |
by iKnowNothing (Scribe) on Jul 13, 2010 at 22:30 UTC | |
by toolic (Bishop) on Jul 14, 2010 at 01:09 UTC |