如何使用 AppleScript 或 Automator 根据文件名更改文件的创建时间? [英] How to change the creation time of files based on filenames using AppleScript or Automator?

查看:24
本文介绍了如何使用 AppleScript 或 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:

for f in *;做 if [[ $(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆