如何用python批次將某資料夾下的所有檔案之建立日期改為修改日期?(For Windows)

NAS 網路磁碟伺服器 使用者俱樂部社團的執行檔

將執行檔放置資料夾中
執行,程式找到根目錄
按下enter程式開始修改檔案建立日期資訊並列出過程,再次按下enter即結束程式
修改前
修改後

原始碼如下: (需安裝filedate模組)

import sys
import os
import datetime
import time

import filedate

def convert_file_created_time_to_modified_time(path):
    f = filedate.File(path)
    pp = f.get()
    print('檔案路徑:', path)
    print('修改日期:', pp['modified'])
    print('建立日期:', pp['created'])
    f.set(
        **dict(pp, created=pp['modified'])
        )
    pp = f.get()
    print('修改建立日期後資訊如下:')
    print('建立日期:', pp['created'])
    print()

app_dir = os.path.dirname(sys.executable)
print(app_dir)
all_dir = [d for d in os.listdir(app_dir) if os.path.isdir(d)]
print('找到的根目錄:')
for d in all_dir:
    print(d)
input('按下Enter開始執行')
for dd in all_dir:
    for r, d, n in os.walk(dd):
        for f in n:
            convert_file_created_time_to_modified_time(os.path.join(r, f))

input('按下Enter結束')

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *