本文介绍了如何获取文件计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码可以正常运行,但是我真的不希望它给我一个带有名称的消息框.我想获得一个计数,而不是那里的文件数.我该如何重做以便获得计数?谢谢.

This code runs and works well, but I don''t really want it to give me a messagebox with names. I want to get a count instead of the number of files there are instead. How can I rework this so that I get a count? Thank you.

int GetFileList(const wchar_t *searchkey, std::map<std::wstring,> &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);
        map[fd.cFileName] = buf;
        if(FindNextFile(h, &fd) == FALSE)
            break;
    }
    return map.size();
}

void main()
{ 
    std::map<std::wstring,> map;
    int count = GetFileList(L"C:\\Users\\DS\\Downloads\\*.zip", map)
    && GetFileList(L"C:\\Users\\DS\\Downloads\\*.txt", map);
	for(std::map<std::wstring,>::const_iterator it = map.begin(); 
      it != map.end(); ++it)
    {
      MessageBoxW(NULL,it->first.c_str(),L"File Name",MB_OK);
	  MessageBoxW(NULL,it->second.c_str(),L"File Date",MB_OK);
    }
} 

推荐答案


这篇关于如何获取文件计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:27