My Marantz PMD-620 has a reliable internal clock, and stamps the files with the time that recording stopped. File times are remarkably fragile, so I wanted to make sure that the times were preserved in the file name. Perl’s rename utility does this rather well, as it allows you to use arbitrary code in a rename operation. So:
rename -n 'use POSIX qw(strftime); my $mtime=(stat($_))[9]; s/.WAV$//; $_ .= strftime("-%Y%m%d%H%M%S",localtime($mtime)); s/$/.WAV/;' *.WAV
which, for files 1007.WAV and 1008.WAV recorded last night, results in:
1007.WAV renamed as 1007-20091024192436.WAV
1008.WAV renamed as 1008-20091024193438.WAV
To actually rename the files, remove the -n
from the command line. I left it in so you couldn’t blame me for b0rking up your files if you typed first, thought later.
There are probably smarter ways to handle the file extension. This works for me. Perfection comes later.