skingsbu1
asked on
Issue renaming a file
I am having an issue renaming a file with the File::Find module.
my @initial_directory = ("/Users/test/Development/ sandbox/fi le_strip_e xample/fil es");
find (\&wanted, @initial_directory);
sub wanted {
return unless /\s$/;
my $new_name = $File::Find::name;
$new_name =~ s/ +$//; # Remove trailing spaces in the filename
chomp $new_name;
print "Renaming >>$File::Find::name<< to >>$new_name<<\n";
rename $File::Find::name, $new_name;
}
In that location there is a file named: testFile with a space at the end of the name. For some reason i am unable to strip the space at the end of the file.
my @initial_directory = ("/Users/test/Development/
find (\&wanted, @initial_directory);
sub wanted {
return unless /\s$/;
my $new_name = $File::Find::name;
$new_name =~ s/ +$//; # Remove trailing spaces in the filename
chomp $new_name;
print "Renaming >>$File::Find::name<< to >>$new_name<<\n";
rename $File::Find::name, $new_name;
}
In that location there is a file named: testFile with a space at the end of the name. For some reason i am unable to strip the space at the end of the file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what was $! after it returned?