20.2.3 Example: Changing a File Time to the Current Time

The following code sets the creation time for a file to the current system time:

HANDLE hf;

FILETIME ft;

SYSTEMTIME st;

/* open ftime.c for write access */

hf = CreateFile("\\ftime.c", GENERIC_WRITE, 0,

(LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING,

FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL);

if (hf == INVALID_HANDLE_VALUE) {

puts("could not open ftime.c");

ExitProcess(1);

}

GetSystemTime(&st); /* get current time */

SystemTimeToFileTime(&st, &ft); /* convert to file time format */

SetFileTime(hf, &ft, /* set creation time for file */

(LPFILETIME)NULL, (LPFILETIME)NULL);