【发布时间】:2018-06-04 19:13:41
【问题描述】:
我正在尝试使用 SetFile 更改 MacOS 文件的创建和修改日期 (see here)。
我的问题有点类似于 this one,但即使按照那里的建议,我也无法让它工作并得到错误 1 作为回报(语法错误)
代码如下:
file_t = obj.decided_stamp.strftime('%m/%d/%Y %H:%M:%S')
# Use SetFile to change creation and modification date
cmd = ['SetFile', '-d', '-m', '{0}{1}{0}'.format('\'', file_t),
'{0}{1}{0}'.format('\'', obj.path)]
try:
check_output(cmd, shell=True)
except Exception as e:
logger.warning('Error {} on {} using {}'.format(e, obj.path, cmd))
如果我去掉 shell=True 我得到错误 2(其他错误),使用 shell 给出错误 1。
这是我得到的警告打印示例:
2018-06-04 21:06:06 main[84988] 警告错误命令 '['SetFile', '-d', '-m', "'01/13/2017 14:55:55'", "'/Volumes/Images/2017-01-12 Conference/2017-01-13 14.55.55.jpg'"]' 返回非零退出状态 2. on /Volumes/Images/ 2017-01-12 Conference/2017-01-1314.55.55.jpg 使用 ['SetFile', '-d', '-m', "'01/13/2017 14:55:55'", "'/ Volumes/Images/2017-01-12 Conference/2017-01-13 14.55.55.jpg'"]
知道我在哪里做错了吗?
谢谢
【问题讨论】:
标签: python python-3.x macos subprocess