Non Recursive Folder Traversal
-
The usual technique of traversing a folder and all it's sub-folders is pretty commonplace, but it suffers from the fact that the stack just might run out (sure, we can specify the stack size in vc, but we dont want to hog a lot of memory for the stack!). What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? :eek: Bikram
-
The usual technique of traversing a folder and all it's sub-folders is pretty commonplace, but it suffers from the fact that the stack just might run out (sure, we can specify the stack size in vc, but we dont want to hog a lot of memory for the stack!). What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? :eek: Bikram
Bikram Singh wrote: What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? Sure there is. Just call
SetCurrentDirectory()
with each directory encountered.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
The usual technique of traversing a folder and all it's sub-folders is pretty commonplace, but it suffers from the fact that the stack just might run out (sure, we can specify the stack size in vc, but we dont want to hog a lot of memory for the stack!). What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? :eek: Bikram
If your program in a Win32 app with a message loop you could use PostMessage to do the whole thing asynchronously, and then in the main function use a event loop to wait till it was all done. Dunno how efficient that is :) ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned
-
Bikram Singh wrote: What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? Sure there is. Just call
SetCurrentDirectory()
with each directory encountered.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
Do you have some source code for the entire problem? Bikram
-
Do you have some source code for the entire problem? Bikram
No. I've personally not ever used the function. It's a hold-over from the Unix world and its single-threaded environment. For Windows and multi-threaded applications, if another thread is running, the "current directory" is constantly changing for all of the threads. For anything that requires folder traversal, I always use recursion. Can you explain in more detail your hesitation in using this methodology?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
The usual technique of traversing a folder and all it's sub-folders is pretty commonplace, but it suffers from the fact that the stack just might run out (sure, we can specify the stack size in vc, but we dont want to hog a lot of memory for the stack!). What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? :eek: Bikram
Search in this board for an algorithm I posted a week ago or so to recurse a directory. This uses SetCurrentDirectory() and uses minimal stack. Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
Search in this board for an algorithm I posted a week ago or so to recurse a directory. This uses SetCurrentDirectory() and uses minimal stack. Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
I tried this for almost an hour yesterday because I knew I had just recently seen an example. All that I could find was a post from coremn.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
The usual technique of traversing a folder and all it's sub-folders is pretty commonplace, but it suffers from the fact that the stack just might run out (sure, we can specify the stack size in vc, but we dont want to hog a lot of memory for the stack!). What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? :eek: Bikram
It's pretty easy. Something like:
CStringList dirs, files; CString dir; CFileFind ff; BOOL ok; dirs.AddTail("c:\\work\\lisp"); while (!dirs.IsEmpty()) { dir = dirs.RemoveHead(); if (ff.FindFile( dir + "\\*.*" )) { do { ok = ff.FindNextFile(); if (ff.IsDots()) continue; if (ff.IsDirectory()) { dirs.AddTail( ff.GetFilePath() ); continue; } files.AddTail( ff.GetFilePath() ); }while (ok); } }
-- Joel Lucsy