Is there a C function call that can change the last modified date of a file or directory in Windows?
You can use the SetFileTime function, for the directories, you have to use the CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag to get the directory handle and use it as the file handle parameter of the SetFileTime like this:
hFolder = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_BACKUP_SEMANTICS, NULL);
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 pasted the wrong function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With