代码 :
import os import time,datetime def change_file_time(file_path, new_timestamp): # 使用stat函数获取文件的状态 file_stat = os.stat(file_path) # 更新文件的访问时间和修改时间 os.utime(file_path, (file_stat.st_atime, new_timestamp)) # 输出文件的新访问时间和修改时间 new_atime = os.path.getatime(file_path) new_mtime = os.path.getmtime(file_path) print(f"文件的新访问时间:{time.ctime(new_atime)}") print(f"文件的新修改时间:{time.ctime(new_mtime)}") fpath = input("请输入文件路径:") newtime_str = str(input("请输入修改日期yyymmdd:")) date_format = "%Y%m%d" newtime = datetime.datetime.strptime(newtime_str,date_format) ntstamp = newtime.timestamp() print(newtime) change_file_time(fpath,ntstamp)
标签:文件,python,newtime,time,修改,file,new,path,os From: https://www.cnblogs.com/pu369/p/18111165