python如何不改动文件的情况下修改文件的 修改日期

有个需求是我需要把目录下所有的excel的修改时间统一,想写个python脚本,刚开始天真的以为重命名就行了,其实是不行的。
然后找了几个操作excel的库(openpyxl,xlutils),想打开然后再保存,结果要么不支持读取xlsx的格式,要么。。总之格式上总归有点瑕疵,会破坏原来的样式。。
所以有没有其他的办法,效果相当于打开再保存一下这个文件(excel)

阅读 6.4k
4 个回答

os.utime

Help on built-in function utime in module posix:

utime(...)
    utime(path, (atime, mtime))
    utime(path, None)

    Set the access and modified time of the file to the given values.  If the
    second form is used, set the access and modified times to the current time.
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题