Skip to content

Instantly share code, notes, and snippets.

@johnmave126
Created July 5, 2013 09:57
Modify file time on windows
#include <windows.h>
#include <stdio.h>
#include <string.h>
int main(void) {
FILE *fp;
char name[1024];
SYSTEMTIME base_time;
FILETIME base_time_f;
HANDLE fd;
GetSystemTime(&base_time);
base_time.wMonth--;
fp = fopen("list", "r");
while(!feof(fp)) {
fgets(name, 1024, fp);
if(name[strlen(name) - 1] == '\n') {
name[strlen(name) - 1] = '\0';
}
fd = CreateFile(name, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(fd == INVALID_HANDLE_VALUE) {
fprintf(stderr, "%d\n", GetLastError());
return 1;
}
SystemTimeToFileTime(&base_time, &base_time_f);
SetFileTime(fd, &base_time_f, &base_time_f, &base_time_f);
base_time.wHour += (base_time.wMinute + 1) / 60;
base_time.wMinute = (base_time.wMinute + 1) % 60;
CloseHandle(fd);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment