rename a file to add its creation date and (optionally) time stamp to the beginning of the file name. uses mdls to get the content creation date and time.
YYYMMDDTHHMMSS filename
rename-to-creation.pl [--time] [--git] [--email] [-x] files--email the file is an email; look for the "Date: " email header and convert its timezone, and use the email date if it's before the creation date. This is handy for emails you've dragged out of Mail.app to the finder; their creation time will be the time of the drag.
--git prepend the mv command with git
--time if specified, will also add 'Ttimestamp' to the filename.
-x or --x this flag causes the actual mv command to run; without this, rename-to-creation.pl just prints out what it would do but doesn't do anything.
remember, it won't actually do the move until you add the --x flag. and you can use any shell globbing commands, such as *.txt or insurance*.pdf.
Note: this doesn't care if it's a file or a folder.
rename-to-creation.pl old.jpgwill look for a file name "old.jpg", use mdls to get its kMDItemContentCreationDate, and than rename the file. let's assume the file was created 2023-10-08 at 4:17:11pm (localtime). you'd see:
old.jpg
mv "old.jpg" "20231008 old.jpg"with the same file, if you ran rename-to-creation.pl --time old.jpg you'd see
old.jpg
mv "old.jpg" "20231008T161711 old.jpg"if you have filenames that start with a dash (-), add -- first; this tells the commandline parser to stop looking for options and flags.
rename-to-creation.pl --time --email -- --\ file\ starting\ with\ dash.emlfor really difficult names, try with find and xargs (only do this in a folder with no subfolders). I settled on this while trying to rename a folder with 8,000 old emails in it.
find . -type f -print0 |xargs -0 rename-to-creation.pl --email --time --