diff options
| author | B. Watson <yalhcru@gmail.com> | 2015-04-08 03:18:53 -0400 | 
|---|---|---|
| committer | B. Watson <yalhcru@gmail.com> | 2015-04-08 03:18:53 -0400 | 
| commit | 122f3c401f23f84799802c7b9667bda222646487 (patch) | |
| tree | bc77cc44c516eac71b2d6490574fd32a5b5efd65 /renumfiles | |
| download | misc-scripts-122f3c401f23f84799802c7b9667bda222646487.tar.gz | |
initial commit
Diffstat (limited to 'renumfiles')
| -rwxr-xr-x | renumfiles | 33 | 
1 files changed, 33 insertions, 0 deletions
diff --git a/renumfiles b/renumfiles new file mode 100755 index 0000000..28ff2b9 --- /dev/null +++ b/renumfiles @@ -0,0 +1,33 @@ +#!/usr/bin/perl -w + +sub usage { +	die "Usage: renumfiles <-fake> <startnum> pattern [files ...]\n"; +} + +if($ARGV[0] =~ /^--?f(?:ake)?$/) { +	$fake = 1; +	shift; +} + +$num = 1; +if($ARGV[0] =~ /^\d+$/) { +	$num = $ARGV[0]; +	shift; +} + +$pattern = $ARGV[0] || usage; +$pattern =~ s/\%d/%02d/; +if($pattern !~ /\%\d+d/) { +	$pattern = "${pattern}_\%02d.jpg"; +} +shift; + +@files = @ARGV; +usage unless @files; + +for(@files) { +	my $new = sprintf($pattern, $num); +	warn "'$_' => '$new'\n"; +	rename($_, $new) unless $fake; +	$num++; +}  | 
