#!/usr/bin/perl use strict; (print <) { next if /new/; chomp; my ($new, $old) = split; $MAP{$new} = $old; } close($fh); my $next = 1; foreach my $done (sort { my ($aa) = $a =~ /(\d+)/; my ($bb) = $b =~ /(\d+)/; $aa <=> $bb; } glob 'x/*.jpg') { my ($num) = $done =~ /(\d+)/; while (-e "$next.jpg") { $next++ } print "mv $done $next.jpg\n"; rename($done, "$next.jpg") if !$OPT_V; my $raw = "raw/$num.jpg"; if ($raw ne "raw/$next.jpg" && -e $raw) { print "mv $raw raw/$next.jpg\n"; rename($raw, "raw/$next.jpg") if !$OPT_V; } $MAP{$next} ||= $num; $next++; } if (glob('x/*') == 0) { print "rmdir x\n"; rmdir('x') if !$OPT_V; } if (glob('trash/*') == 0) { print "rmdir trash\n"; rmdir('trash') if !$OPT_V; } if (-e '.tmp') { print "rm .tmp\n"; unlink('.tmp') if !$OPT_V; } if ($next > 1) { if (!-e 'captions.txt') { print "create captions.txt\n"; if (!$OPT_V) { open(my $fh, '>captions.txt'); print $fh "# vim: noet ts=6\n"; for (my $i=1; $i<$next; $i++) { print $fh "$i\t\n"; } close($fh); } } else { open(my $fh, ') { $last = $1 if /^(\d+)/; } close($fh); if ($last+1 < $next) { printf "update captions.txt (%d to %d)\n", $last+1, $next-1; if (!$OPT_V) { open(my $fh, '>>captions.txt'); for (my $i=$last+1; $i<$next; $i++) { print $fh "$i\t\n"; } close($fh); } } } print "update raw/map.txt\n"; if (!$OPT_V) { open(my $fh, '>raw/map.txt') or warn "Couldn't write raw/map.txt: $!\n"; printf $fh "%-4s %s\n", 'new', 'old'; foreach (sort {$a <=> $b} keys %MAP) { printf $fh "%-4d %d\n", $_, $MAP{$_} % 1000; } close($fh); } } print "Nothing to do.\n" if $next == 1;