您的位置:首頁技術文章
文章詳情頁

python如何不改動文件的情況下修改文件的 修改日期

瀏覽:148日期:2022-06-28 09:34:21

問題描述

有個需求是我需要把目錄下所有的excel的修改時間統一,想寫個python腳本,剛開始天真的以為重命名就行了,其實是不行的。然后找了幾個操作excel的庫(openpyxl,xlutils),想打開然后再保存,結果要么不支持讀取xlsx的格式,要么。。總之格式上總歸有點瑕疵,會破壞原來的樣式。。所以有沒有其他的辦法,效果相當于打開再保存一下這個文件(excel)

問題解答

回答1:

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.回答2:

shutil.copy

回答3:

是什么系統啊,如果是linux,直接touch不就好了,非要這么折騰

回答4:

復制一份源文件再重命名,再刪除源文件.

標簽: Python 編程
相關文章:
国产综合久久一区二区三区