Recommended Posts

I have writtin a function that will scan thought all directories and sub directories and record all files into a big text file. later it will be used to look for files of a certain type. like *.bmp.. but for the moment it finds every thing. I useed FindNextFile/FindFirstFile.
it works great except for one problem, when it comes to scanning each drive, the order in which I scan them will cause problems

why would I have to scan the drives in reverse order? why can''t i scan from c:\ down to the last drive? can anyone lend me some insight into this problem?
"I seek knowledge and to help those who also seek it"

0

Share this post

Link to post

Share on other sites

Advertisement

Guest Anonymous Poster

Share this post

Link to post

Share on other sites

What? Im saying that I can only scan the drives in reverse order, if I try forward order it gives me the error ERROR_FILE_NOT_FOUND. but when I do it backwards it gives no errors and succsessfully compiles the list.

Does anyone know what could cause this?

0

Share this post

Link to post

Share on other sites

AP is trying to say you did not give enough information. You should post some code so we can see how you are calling FindNextFile. But, I understand your question. There are bugs with FindNextFile especially in how it deals with long filenames. Sorry I don''t know the exact nature of the bugs, but they can cause FindNextFile can return ERROR_FILE_NOT_FOUND for no apparent reason sometimes. You should not check for ERROR_FILE_NOT_FOUND when using FindNextFile. Just check to see if it returns a non zero value (this is in the MSDN docs). But, I am just guessing since I don''t know how you actually have it coded.

static void WalkPath(LPCTSTR szRootDir, LPCTSTR szSearchPattern){ // We do an iterative algorithm, therefore we keep a queue // of directories to search through. We looop through // everything we find. If we find a directory, add it // to that queue. // Then all we need to do is to keep searching directories // until that queue is empty, in which case we're ready. // Seed in the queue is the directory the user gave to // this function. std::queue DirectoriesToWalk; DirectoriesToWalk.push(szRootDir);

// Used for FindFirstFile, re-use the string for performance String FileName;

while ( !DirectoriesToWalk.empty() ) { // take a directory to search from the queue const String CurrentRoot = DirectoriesToWalk.front(); DirectoriesToWalk.pop();