【发布时间】:2011-04-09 22:12:25
【问题描述】:
CFindFile 的文档指出
如果有更多文件,则非零;零 如果找到的文件是最后一个 目录或如果发生错误。 要获取扩展的错误信息, 调用 Win32 函数 GetLastError。 如果找到的文件是最后一个文件 目录,或者如果没有匹配的文件 可以发现,GetLastError 函数返回 ERROR_NO_MORE_FILES。
如果对 FindNextFile 的调用返回相同的值,我如何知道我有 1 个文件还是 0 个文件?
如果找到零个文件,对 FindFile::GetFilePath() 的调用似乎会失败(这会无意中导致我的应用程序崩溃)。
pLog->Log(_T("Finding files in [%s]"), 1, szFilePath);
if (!oFindFile.FindFile(szFilePath, 0))
{
pLog->Log(_T("Failed to find file in directory: [%s]"),1,szDirectory);
return false;
}
bool moreFiles = true;
while(moreFiles)
{
moreFiles = oFindFile.FindNextFile();
if (oFindFile.IsDots())
{
continue;
}
CString szFileName = oFindFile.GetFilePath();
pLog->Log(_T("Found file [%s]"), 1, szFileName);
pVector->push_back(szFileName);
}
return true;
编辑
CString szFilePath = _T("C:\documents and settings\username\desktop\*.lnk");
CString szDirectory = T("C:\documents and settings\username\desktop");
【问题讨论】:
标签: c++ visual-studio-2008 mfc