#!/usr/bin/perl -w # requires GNU ls on your system. @fnames=(); @fdates=(); if (!open(PH, "/bin/ls -l --time-style=+%y%m%d p[1-9abc][0-9]?????.[jm][po][gv]|")) { print(STDERR "Rename olympus pnnnkkkk.jpg/.mov filenames to yymmdd-kkk format.\n". "The file timestamp is used rather than the first 4 letters.\n"); } while () { @f = split(" "); push(@fnames, $f[6]); push(@fdates, $f[5]); } foreach $i (0..$#fnames) { $fn = $fnames[$i]; $dt = $fdates[$i]; $fn =~ m/^p.*?([^0]?...)\.(...)$/; $num = $1; $ext = $2; $nfn = "$dt-$num.$ext"; chmod(0644, $fn); rename($fn, $nfn) || die("$fn -> $nfn: $!\n"); }