#!/usr/bin/perl use Getopt::Std; use Pod::Usage; use strict; use warnings; use POSIX qw(log10 ceil); my (%option); getopts("hx:X:nNc", \%option) ; if ($option{h}) { pod2usage(-verbose => 2); die("\n\n"); } my $infix = ''; if ($option{X}) { $infix = $option{X}; } elsif ($option{x}) { $infix = '-' . $option{x} ; $infix =~ s/\s+/-/g; $infix =~ s/-+/-/g; } my $nf_option; if ($option{N}) { my $suffix = '%0' . digits_required(scalar(@ARGV)) . 'i'; $nf_option = '%Y%m%d-%H%M-' . $infix . '-' . $suffix ; } else { $nf_option = '%Y%m%d-%H%M%S' . $infix ; } if ($option{c}) { foreach my $file (@ARGV) { my $individual_nf = $nf_option; if ($file =~ /P.\d\d(\d\d\d\d)\.\S+$/) { $individual_nf = 'p' . $1 . '-' . $nf_option; } my @command = ('jhead', '-exonly', '-nf' . $individual_nf, $file); print("Executing:\n@command\n"); unless ($option{n}) { system(@command); } } } else { my @command = ('jhead', '-exonly', '-nf' . $nf_option, @ARGV); print("Executing:\n@command\n"); unless ($option{n}) { system(@command); } } ##### end main sub digits_required { # arg: nbr of files to process # return: nbr of digits to count them my $digits = ceil (log10($_[0])); $digits = 1 if ($digits < 1); return $digits; } ################################################## ##### DOCUMENTATION ################################################## =head1 Documentation =head2 Synopsis COMMAND OPTION(S) [FILE(S)] =head2 Options =over =item -h Get this info and quit. =item -c Put the last four digits of the main part of the filename before the date (to help deal with clock failures on the Canon). =item -X I Make file names like B<20070529I01.jpg> without altering the string I. =item -x I Make file names like B<20070529-I-01.jpg>; spaces will be converted to hyphens and multiple hyphens will be regularized to singles ones. =item -N Use sequential numbers instead of seconds. =item -n Dry run (do not rename). =back =cut