Cambio de una hora de archivo a la hora actual

En el ejemplo siguiente se establece la hora de última escritura de un archivo en la hora actual del sistema mediante la función SetFileTime .

El sistema de archivos NTFS almacena los valores de hora en formato UTC, por lo que no se ven afectados por los cambios en la zona horaria o el horario de verano. El sistema de archivos FAT almacena los valores de hora en función de la hora local del equipo.

El archivo debe abrirse con la función CreateFile mediante FILE_WRITE_ATTRIBUTES acceso.

#include <windows.h>

// SetFileToCurrentTime - sets last write time to current system time
// Return value - TRUE if successful, FALSE otherwise
// hFile  - must be a valid file handle

BOOL SetFileToCurrentTime(HANDLE hFile)
{
    FILETIME ft;
    SYSTEMTIME st;
    BOOL f;

    GetSystemTime(&st);              // Gets the current system time
    SystemTimeToFileTime(&st, &ft);  // Converts the current system time to file time format
    f = SetFileTime(hFile,           // Sets last-write time of the file 
        (LPFILETIME) NULL,           // to the converted current system time 
        (LPFILETIME) NULL, 
        &ft);    

    return f;
}