in reply to regex renaming with existing files
its a basic counter. you can also put in two counters and rename both sides of the if statement. there is also File::Find and its pretty easy to adjust to :)use strict; use warnings; my $existingFile; my $filename; print "provide filename: "; $existingFile = <STDIN>; $filename = "folder1"; chomp $existingFile; chomp $filename; my $counter = 1; #declare counter if (-e $filename) { print "File Exists! Renaming with .[x]\n"; $counter++; #increment already declared counter with value +assigned rename "$existingFile", "$filename.[$counter]"; } else { rename "$existingFile", "$filename"; } exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex renaming with existing files
by GrandFather (Saint) on Nov 04, 2014 at 09:47 UTC | |
by james28909 (Deacon) on Nov 04, 2014 at 10:24 UTC | |
by GrandFather (Saint) on Nov 04, 2014 at 20:07 UTC | |
by ArifS (Beadle) on Nov 04, 2014 at 14:26 UTC | |
by GrandFather (Saint) on Nov 04, 2014 at 20:12 UTC |