#!/usr/bin/perl # redate - move file to foo-19981211 # tchrist@perl.com # Sat Apr 17 20:08:27 MDT 1999 $oops = 0; if (@ARGV && $ARGV[0] eq '-n') { shift; $nonono = 1; } die "usage: $0 [-n] filename ...\n" unless @ARGV; for $file (@ARGV) { next if $file =~ /-\d{8}$/; # already done unless ($mtime = (stat($file))[9]) { warn "$0: can't stat $file: $!\n"; $oops++; } ($day, $month, $year) = (localtime($mtime))[3,4,5]; $then = sprintf "%4d%02d%02d", $year + 1900, $month + 1, $day; if ($nonono) { print "rename $file $file-$then\n"; next; } next if rename($file, "$file-$then"); warn "$0: can't rename `$file' to `$file-$then': $!\n"; $oops++; } exit ($oops != 0); __END__