Adjusting a Search Time
I'm doing a search on files. I need to adjust the search time from the current t开发者_StackOverflow社区ime (filetime) to current time(file time) less one minute. How would I do this. Thisis what I have so far. Thank you.
struct file_data
{
std::wstring sLastAccessTime;
__int64 nFileSize;
};
int GetFileList(const wchar_t *searchkey, std::map<std::wstring, file_data> &map)
{
WIN32_FIND_DATA fd;
HANDLE h = FindFirstFile(searchkey,&fd);
if(h == INVALID_HANDLE_VALUE)
{
return 0; // no files found
}
while(1)
{
wchar_t buf[128];
FILETIME ft = fd.ftLastWriteTime;
SYSTEMTIME sysTime;
FileTimeToSystemTime(&ft, &sysTime);
wsprintf(buf, L"%d-%02d-%02d",sysTime.wYear, sysTime.wMonth, sysTime.wDay);
file_data filedata;
filedata.sLastAccessTime= buf;
filedata.nFileSize = (((__int64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;
map[fd.cFileName]= filedata;
if (FindNextFile(h, &fd) == FALSE)
break;
}
return map.size();
}
int main()
{
std::map<std::wstring, file_data> map;
GetFileList(L"C:\\Users\\DS\\Downloads\\*.jpg", map);
GetFileList(L"C:\\Users\\DS\\Downloads\\*.txt", map);
int count = GetFileList(L"C:\\Users\\DS\\Downloads\\*.pdf", map);
for(std::map<std::wstring, file_data>::const_iterator it = map.begin();
it != map.end(); ++it)
{
Use GetSystemTimeAsFileTime
to get the current time in FILETIME
format. Subtract 6000000000 to go back in time one minute. Use CompareFileTime
to compare each file's time against that value.
精彩评论