Skip to main content
 首页 » 编程设计

python之如何在 Python 中将文件触摸到某个日期时间

2025年01月19日9xxx_UU

在 Linux 中,我可以使用 touch 更改文件的创建日期:

touch -a -m -t 201512180130.09 file.txt 

在 Python 中,我可以使用 touch 命令更改创建日期,但我没有看到任何参数来将其设置为与当前日期不同的日期。

from pathlib import Path 
Path('path/to/file.txt').touch() 

如何在 Python 中设置日期?

请您参考如下方法:

也可以在python中调用touch命令

from subprocess import call 
call(["touch","-a","-m","-t","201512180130.09","file.txt"])