[英]How to modify the file modification date with python on mac?
Title says it all. 标题说明了一切。 I am trying to modify the file modification dates of folders.
我正在尝试修改文件夹的文件修改日期。
touch t- YYYYMMDDhhmm
command from terminal does it, but it also changes the file creation date, which I do not want to change. 从终端
touch t- YYYYMMDDhhmm
命令可以执行此操作,但是它也更改了文件创建日期,我不想更改它。
Is there a solution to this problem? 有解决这个问题的方法吗?
os.utime
can be used to change the modification and/or access time of a file. os.utime
可用于更改文件的修改和/或访问时间。
It accepts a descriptor or path-like object, and a tuple of times in either seconds or nanoseconds. 它接受一个描述符或类似路径的对象,以及以秒或纳秒为单位的时间元组。 These specify the latest access and modification times, respectively.
它们分别指定最新的访问和修改时间。 For example:
例如:
>>> import os
>>> with open('tmp', 'wt') as f: pass
...
>>> result = os.stat('tmp')
>>> print(result.st_atime, result.st_mtime)
1541131715.0 1541131715.0
>>> os.utime('tmp', (result.st_atime, result.st_mtime + 1.0))
>>> result = os.stat('tmp')
>>> print(result.st_atime, result.st_mtime)
1541131715.0 1541131716.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.