【发布时间】:2016-09-21 22:46:58
【问题描述】:
有没有办法使用 python “触摸” Linux 中的现有目录,使其 modtime 成为当前系统时间?
在命令行中,这相当于touch $directory。
【问题讨论】:
标签: python linux python-3.x
有没有办法使用 python “触摸” Linux 中的现有目录,使其 modtime 成为当前系统时间?
在命令行中,这相当于touch $directory。
【问题讨论】:
标签: python linux python-3.x
您可以使用os.utime:
now = time.time()
os.utime('/tmp/marker', (now, now))
【讨论】:
time.time()——从Python 2.0开始,你只需使用os.utime('/tmp/marker', None)就可以达到同样的效果。
os.utime() 将允许您设置现有文件系统对象的 atime 和 mtime,默认为当前日期和时间。
os.utime(path)
【讨论】:
None 来获取当前日期和时间。