gpt4 book ai didi

windows - 为什么 FindNextFile 在 Windows 7 上失败

转载 作者:可可西里 更新时间:2023-11-01 09:41:42 25 4
gpt4 key购买 nike

此代码在家庭 Windows XP 上运行,但在 64 位 Windows 7 上运行失败。尽管提供的文件夹中有 50 多个文件,但甚至一次都没有进入循环。不仅不进入,还为GetLastError返回ERROR_NO_MORE_FILES。为什么?

string dir = "d:\\validfolder";
WIN32_FIND_DATA ffd;
HANDLE h = FindFirstFile(dir.c_str(), &ffd);
while(FindNextFile(h, &ffd))
{
// some operation
}
DWORD dw = GetLastError();// returns ERROR_NO_MORE_FILES

我尝试了 Wow64DisableWow64FsRedirection 但没有效果。

最佳答案

您需要在您的目录中添加一个文件通配符:

string dir = "d:\\validfolder\\*";

用于列出目录中的文件。否则,您只是询问有关目录本身的信息。

至少我是这样阅读 FindFirstFile 的文档的

To examine a directory that is not a root directory, use the path to that directory, without a trailing backslash. For example, an argument of "C:\Windows" returns information about the directory "C:\Windows", not about a directory or file in "C:\Windows". To examine the files and directories in "C:\Windows", use an lpFileName of "C:\Windows*".

我不知道为什么它在 XP 上对你有用

关于windows - 为什么 FindNextFile 在 Windows 7 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9046275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com