如何在Windows中以编程方式设置文件的修改时间?

最佳答案

Windows(或标准CRT)具有与UNIX相同的utimes函数系列。

struct _utimebuf t;
t.tma = 1265140799;  // party like it's 1999
t.tmm = 1265140799;
_utime(fn, &t);

使用Win32函数,可以使用FILE_BASIC_INFO设置SetFileInformationByHandle
FILE_BASIC_INFO b;
b.CreationTime.QuadPart = 1265140799;
b.LastAccessTime.QuadPart = 1265140799;
b.LastWriteTime.QuadPart = 1265140799;
b.ChangeTime.QuadPart = 1265140799;
b.FileAttributes = GetFileAttributes(fn);
SetFileInformationByHandle(h, FileBasicInfo, &b, sizeof(b));

10-08 11:52