FndFirstFile(),FindNextFile()不允许轻松重入 [英] FndFirstFile(), FindNextFile() do not allow for easy re-entrance
问题描述
FndFirstFile(),FindNextFile()不允许轻松重新进入。
FndFirstFile(), FindNextFile() do not allow for easy re-entrance.
我发现这两个Win32 API函数我认为应该允许我做类似的事情
I had discovered that these 2 Win32 API functions and their equivalents I had thought should allow me to do something like
void WalkDirTree(std::string rootDir, std::string filespec) {
...
HANDLE h=FindFirstFile(...);
...
if (it's a dir and filename not "." and not "..") {
dirpath=rootDir+struct.filename;
WalkDirTree(dirpath,filespec);
} else if (it's a file) {
filepath=rootDir+struct.filename
ProcessFile(filepath)
}
while (FindNextFile(h, ...)) {
...
if (it's a dir and filename not "." and not "..") {
dirpath=rootDir+struct.filename;
WalkDirTree(dirpath,filespec);
else if it's a file
filepath=rootDir+struct.filename;
ProcessFile(filepath);
}
}
但事实并非如此,我必须首先收集所有当前的目录和文件然后在FindNextFile()完成后处理它们。只有这样我才能做递归。在FindFirstFile()或FindNextFile()或相关的
函数中不允许重新进入。
but this is not the case, I must collect all the current dir directories and files first and afterwards process them when FindNextFile() is completed. only then can I do recursion. no re-entrance is allowed within FindFirstFile() or FindNextFile() or related functions.
typedef std::vector<std::string> VS;
WalkDirTree(std::string rootDir, std::string filespec) {
VS dirs;
...
HANDLE h=FindFirstFile(...);
...
if (it's a dir and filename not "." and not "..") {
dirpath=rootDir+struct.filename
dirs.push_back(dirpath)
} else if (it's a file) {
filepath=rootDir+struct.filename
ProcessFile(filepath)
}
while (FindNextFile(h, ...)) {
...
if it's a dir and filename not "." and not ".." {
dirpath=rootDir+struct.filename;
dirs.push_back(dirpath);
} else if (it's a file) {
filepath=rootDir+struct.filename;
ProcessFile(filepath);
}
}
//post-process the found dirs
for (dirIndex=0; dirIndex < dirs.size(); dirIndex++) {
WalkDirTree(dirs[dirIndex], filespec)
}
}
推荐答案
但事实并非如此,我必须首先收集所有当前的目录和文件,然后在FindNextFile()完成后处理它们。只有这样我才能做递归。在FindFirstFile()或FindNextFile()或相关的
函数中不允许重新进入。
but this is not the case, I must collect all the current dir directories and files first and afterwards process them when FindNextFile() is completed. only then can I do recursion. no re-entrance is allowed within FindFirstFile() or FindNextFile() or related functions.
我不知道知道你为何相信这一点,我不相信这是事实。我没看到你的第一个代码有什么问题。
I don't know why you believe this, and I don't believe this is the case. I don't see what is wrong with your first code.
这篇关于FndFirstFile(),FindNextFile()不允许轻松重入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!