How can I use C to change the last modified date of a file on Windows?
3 answers
You can use the SetFileTime function , for directories you have to use CreateFile with the FILE_FLAG_BACKUP_SEMANTICS flag to get the directory handle and use it as the SetFileTime file handle parameter like this:
hFolder = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_BACKUP_SEMANTICS, NULL);
+5
source to share
Use SetFileTime:
BOOL WINAPI SetFileTime(
__in HANDLE hFile,
__in_opt const FILETIME *lpCreationTime,
__in_opt const FILETIME *lpLastAccessTime,
__in_opt const FILETIME *lpLastWriteTime
);
Its in winbase.h, so you just need to include windows.h
EDIT: I inserted the wrong function.
+2
source to share