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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |