All -

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:
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.
code:
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 }

In reply to problem using rename by iKnowNothing

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.