my $dir = 'c:/'; my $from = '.pl'; my $to = '.pl.bak'; while (<$dir*$from>) { my ($old,$new); $old = $new = $_; $new =~ s/$from$/$to/; next if $old eq $new; unless (exist($new)) { rename $old, $new and print "Renamed $old $new\n"; } } sub exist { my $file = shift; if (-e $file) { print "File $file exists, owerwrite (y/n) "; return (<> =~ m/^y/i) ? 0 : 1 } return 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Renaming Files
by blakem (Monsignor) on Jul 14, 2001 at 02:10 UTC | |
|
Re: Renaming Files
by AltBlue (Chaplain) on Jul 13, 2001 at 02:28 UTC | |
|
Re: Renaming Files
by Chady (Priest) on Jul 11, 2001 at 16:44 UTC |