Windows 调整搜索时间
我正在搜索文件。我需要将搜索时间从当前时间(文件时间)调整到当前时间(文件时间),缩短一分钟。我该怎么做呢。这就是我目前所拥有的。多谢各位Windows 调整搜索时间,windows,visual-c++,Windows,Visual C++,我正在搜索文件。我需要将搜索时间从当前时间(文件时间)调整到当前时间(文件时间),缩短一分钟。我该怎么做呢。这就是我目前所拥有的。多谢各位 struct file_data { std::wstring sLastAccessTime; __int64 nFileSize; }; int GetFileList(const wchar_t *searchkey, std::map<std::wstring, file_data> &map) { WIN
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)
{
struct file\u数据
{
std::wstring sLastAccessTime;
__int64-nFileSize;
};
int GetFileList(常量wchar\u t*searchkey,std::map&map)
{
WIN32_FIND_DATA fd;
HANDLE h=FindFirstFile(searchkey,&fd);
if(h==无效的\u句柄\u值)
{
返回0;//未找到任何文件
}
而(1)
{
wchar_t buf[128];
FILETIME ft=fd.ftLastWriteTime;
系统时间系统时间;
FileTimeToSystemTime(&ft和&sysTime);
wsprintf(buf,L“%d-%02d-%02d”,sysTime.wYear,sysTime.wMonth,sysTime.wDay);
文件数据文件数据;
filedata.sLastAccessTime=buf;
filedata.nFileSize=(((_int64)fd.nFileSizeHigh)使用GetSystemTimeAsFileTime
以FILETIME
格式获取当前时间。减去600000000以返回一分钟的时间。使用CompareFileTime
将每个文件的时间与该值进行比较。我想获取不到一分钟的文件。谢谢。非常不清楚。使用systemtimetofiletimee并从中减去60*1000*10000LL。这是一分钟前的文件时间。现在我正在从目录中获取所有pdf、txt和jpg文件。但我只想要一分钟或更短的文件。或者我们应该说一分钟或更短的时间!使用ftCreationTime而不是ftLastWriteTime。谢谢。完成,但我在哪里以及如何设置时间-minute。我会想象它在FILETIME中是最好的。听起来不错!我对这个有点陌生。你有一个例子吗?它会在代码中放在哪里?谢谢你,雷蒙德。我希望这些轻推足以让你阅读更多的文档。FILETIME ftNow;GetSystemTimeAsFileTime(&ftNow);auto ftAs64=ftOneMinuteAgo.dwLowDateTime+((未签名的uu int64)ftOneMinuteAgo.dwHighDateTime>32)}谢谢你雷蒙德。你的轻推确实奏效了。我搜索和阅读。我欣赏输入。我是VB程序员,我刚开始学习C++,和我用的东西有很大的不同。我会尝试找出其余的……你会把它放在同一个地方。在将条目添加到地图之前,请检查文件时间。谢谢雷蒙德。可以,但这是最后一部分还是之后还有更多?