如何使用AppleScript或Automator更改基于文件名的文件创建时间? [英] How to change the creation time of files based on filenames using AppleScript or Automator?
问题描述
我有一个包含数千个图片文件的文件夹.每个文件名都以YYYY-MM-DD开头.创建日期"字段有时仅与文件名中的日期匹配.我想为每个图片文件完成此操作:
I have a folder containing thousands of picture files. Each filename starts as YYYY-MM-DD. The Date Created field only sometimes matches the date in the filename. I would like to accomplish this for each picture file:
如果文件名的YYYY-MM-DD与创建日期不匹配,则将创建日期"设置为文件名的YYYY-MM-DD,并将创建时间"设置为11:11:11(HH:MM:SS).
If YYYY-MM-DD of filename does not match Date Created, then set Date Created to YYYY-MM-DD of filename and set Time Created to 11:11:11 (HH:MM:SS).
我究竟该怎么做?仅供参考,我正在使用Mac mini和OS X 10.9,并且一直在转动我的车轮.感谢您的帮助!
How exactly can I do this? FYI, I’m on a Mac mini and OS X 10.9 and have been spinning my wheels. Thanks for your help!
推荐答案
您可以使用如下所示的shell命令:
You could use a shell command like this:
用于*中的f;如果[[$(date -jf%s $(stat -f%B"$ f")+%F)!= $ {f:0:10}]]则执行;然后SetFile -d $ {f:5:2}/$ {f:8:2}/$ {f:0:4}"$ f";mtime = $(GetFileInfo -m"$ f");SetFile -m"$ {mtime:0:10} 11:11:11""$ f";fi;完成
SetFile和GetFileInfo是开发人员工具包的一部分,可以从Xcode的首选项或 http://下载developer.apple.com/downloads/.
SetFile and GetFileInfo are part of the developer tools package that can be downloaded from Xcode's preferences or from http://developer.apple.com/downloads/.
在date命令中,-j禁用设置时间,-f指定格式字符串,%F是类似于2013-12-31的格式.stat -f指定格式字符串,%B为创建(出生)时间.在GetFileInfo和SetFile中,-m是修改时间,-d是创建时间.
In the date command, -j disables setting the time, -f specifies a format string, and %F is a format like 2013-12-31. stat -f specifies a format string and %B is creation (birth) time. In GetFileInfo and SetFile, -m is the modification time and -d is the creation time.
这篇关于如何使用AppleScript或Automator更改基于文件名的文件创建时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!