Summary of Problem: You are converting the wrong data

Desk checking your code, I suspected I understood the error. So I modified your code to show what you are actually asking the rename to do, and it was as expected: You are trying to rename the file to the same name it already has:

use File::Find; use File::Basename; use File::Spec; use strict; find ({ 'wanted' => \&renamefile }, 'c:\\folder1\\folder2'); sub renamefile { my $file = $_; return unless (-f $file); my $dirname = dirname($file); my $file_name = basename($file); my $new_file_name = $file_name; $new_file_name =~ s/\\\\/./g; print "\$file = [$file]\n"; my $resulting_filename = File::Spec->catfile($dirname,$new_file_na +me); print "\$resulting_filename = [$resulting_filename]\n"; rename($file,File::Spec->catfile($dirname,$new_file_name))or die; } C:\Steve\Dev\PerlMonks\P-2013-08-06@1508-Rename-Fail>perl renameFailDe +bug.pl $file = [abc.txt] $resulting_filename = [abc.txt]

Bottom line: You are supplying the unqualified filename and asking it to change all the backslashes (which by definition there are none) to dots.

Since there are no backslashes in an unqualified filename, you get back the same name you supplied.


In reply to Re: rename file name in directory and subdir by marinersk
in thread rename file name in directory and subdir by starface245

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.