New, more-good version here: New script to re-write dates in file names
To-do: Check for administrator privileges or just write the log to
~/. MacOS (nee OS X (nee Mac OS)) has a default user log directory, but GNU does not. I suppose we could check for “~/.log/” and
mkdir if false…
Title explains it pretty well. Uses
egrep to find date,
sed to edit it,
mv to rename, and
read for user confirmation prompt. Which, btw, can’t be done if you are already doing a read without feeding the new
read from somewhere other than
stdin. Hence the
< /dev/tty at that point in the script. So many strangers to thank for sharing their knowledge online. Thanks, strangers! That should do it.
Why this exists is I had a co-worker who added dates to tons of files in the format “01.02.03”, which resulted in files named “Example filename 01.02.03.xmpl” Same for phone numbers. Clearly this is wrong and something must be done about it (now that new ones won’t be cropping up since he.is.gone). You may be asking yourself how he got away with not getting an e-mailed file bounced back for multiple extensions? My educated guess is that he did and kept doing it the dumb way despite that.
Corrects the above format to “+%Y-%m-%d” (YYYY-MM-DD).
This could probably be done with fewer lines or overall be more betterer, but this is like my first whole shell script. Maybe my years of AppleScript are showing. *meh*