I\'m having trouble using GetFileTime and SetFileTime when it comes to directories. Specifically I think my problem is that I am new to the WinAPI and I don\'t think I\'m
Here is a code example on how to set a directory's date based on a DOS date timestamp.
int Directory_SetDosTime(char *Path, unsigned int DosDateTime)
{
FILETIME LocalTime, FileTime;
HANDLE Handle;
SYSTEMTIME SystemTime;
DosDateTimeToFileTime((DosDateTime >> 16), DosDateTime, &LocalTime);
LocalFileTimeToFileTime(&LocalTime, &FileTime);
FileTimeToSystemTime(&FileTime, &SystemTime);
Handle = CreateFile(Path, GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (Handle == INVALID_HANDLE_VALUE)
{
//Unable to open directory
return FALSE;
}
if (SetFileTime(Handle, &FileTime, &FileTime, &FileTime) == 0)
{
//Unable to set directory time
CloseHandle(Handle);
return FALSE;
}
CloseHandle(Handle);
return TRUE;
}
Answer #2: To use CreateFile
to get a handle to a directory, you need to use the FILE_FLAG_BACKUP_SEMANTICS
flag. Using your example:
h1 = CreateFile(itemA, GENERIC_READ, FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
I would guess this would work for Answer #4 as well, but I haven't tried it to confirm.