【发布时间】:2020-05-09 18:04:17
【问题描述】:
我已经实现了以下功能,它将文件的 LastAccess 时间更改为当前系统的最新时间,但是,我希望它将 LastAccess 时间更改为自定义时间。例如,我给函数一个像 1994-04-04 这样的时间,然后它将 LastAccess 时间更改为那个时间。
BOOL SetFileToCurrentTime(const char* arg_path, const char* arg_file_name)
{
HANDLE h_File;
FILETIME ft_FileTime;
SYSTEMTIME st_SystemTime;
char l_c_Path[MAX_PATH];
strcpy(l_c_Path, arg_path);
strcat(l_c_Path, arg_file_name);
h_File = CreateFile(l_c_Path, FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
GetSystemTime(&st_SystemTime); // Gets the current system time
SystemTimeToFileTime(&st_SystemTime, &ft_FileTime); // Converts the current system time to file time format
if (SetFileTime(h_File, &ft_FileTime, &ft_FileTime, &ft_FileTime))
{
CloseHandle(h_File);
return true;
}
else
{
return false;
}
CloseHandle(h_File);
}
我应该如何修改上面的代码来达到目的?
【问题讨论】: