#!/usr/bin/perl # rename files to be a bit calmer (NO MORE SHOUTING) and try to # recognize which camera it came off of (at least between the two i've # owned). # # currently relies upon Mac OS X for putting the appropriate # timestamps when the files are copied; if Image::Info is a standard # (or easily-installed) module, it might be better to use the EXIF # info instead. use strict; use warnings; use File::Basename qw( dirname basename ); use File::Copy qw( move ); use POSIX qw( strftime ); unless ( @ARGV ) { @ARGV = ( glob( "*.JPG" ), glob( "*.NEF" ), glob( "*.AVI" ), glob( "*.THM" ) ); } FILE: foreach my $raw_file ( @ARGV ) { my $dir = dirname $raw_file; my $orig = basename $raw_file; $_ = lc $orig; my $new; if ( /^img_(\d{4}\.jpg)$/ ) # canon s400 { $new = "c$1"; } elsif ( /^mvi_(\d{4}\.avi)$/ ) # canon s400 { $new = "c$1"; } elsif ( /^st(.)_(\d{4})\.(jpg)$/ ) # canon s400 "panorama mode" { $new = "c$2$1.$3"; } elsif ( /^dsc_(\d{4}\.(?:jpg|nef))$/ ) # nikon d70 { $new = "n$1"; } unless ( defined $new ) { print STDERR "unrecognized: $_\n"; next; } my $mtime = (stat $orig)[9]; my $date = strftime '%Y-%m-%d-xxx', localtime $mtime; unless (-d $date) { mkdir $date, 0777 or die "couldn't create dir '$date': $!"; } print "$orig => $date/$new\n"; move "$dir/$orig", "$dir/$date/$new"; }