larus has asked for the wisdom of the Perl Monks concerning the following question:
When I e.g. call this script like this to convert a string "John" to "Matt"#!/bin/perl use warnings; use strict; use File::Find; use File::Copy; my $path = $ARGV[0]; my $from = $ARGV[1]; my $to = $ARGV[2]; die "You must supply a full directory path" unless (-e $path && -d $pa +th); find(\&renamedir, "$path"); sub renamedir { next if -f $_; next if /^\./; my $new_name = $_; $new_name =~ s/$from/$to/g; chdir($File::Find::dir); move($_, $new_name) or die $!; }
I get an error saying that "Can't cd to (C:/Temp/) John : No such file or directory. So, it seems that the problem is that the script changes the folder name before it tries to cd into it. How could I tackle this problem? Thanks!C:\>Replace.pl "C:/Temp/" John Matt
|
|---|