代码:
from win32file import CreateFile, SetFileTime, GetFileTime, CloseHandle,CreateDirectory
from win32file import GENERIC_READ, GENERIC_WRITE, OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS
from pywintypes import Time # 可以忽视这个 Time 报错(运行程序还是没问题的)
import os
def AlterFileFolderTime(path,createTime,accessTime,modifyTime):#修改文件/目录时间。传入的为时间戳
fh=None#文件句柄
try:
if(os.path.isfile(path)):
fh = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, None, OPEN_EXISTING,0 ,