Hi all,

How might you go about traversing directories of a drive? I am able to list all of the top-level directories of my C: drive but I'm not sure how to go about and navigate through the sub-directories. Thanks in advance..
Posted on 2001-11-01 21:02:28 by Eagle17
Time to learn how to program a recrusive algorithm :)

i.e. Every time you find a directory, save your position and call your directory routine again.

Or, do you just want to set the current directory to something other than the root?
Posted on 2001-11-01 22:22:57 by bitRAKE
maybe the default shell directory browse dialog is of use?

if yes, take a look into "SHBrowseForFolder"
Posted on 2001-11-02 03:54:19 by beaster
You can do it via COM Shell methods or use the 'common' win32 APIs.
For the latter approach check the following functions:

FindFirstFile
FindFirstFileEx
FindNextFile

This are used for directory and file traversing.


Your other chance (which i would not recommend if you are not very experienced) is to use the 'Next ' method from the IEnumIDList interface together with "IShellFolder's " GetDisplayNameOf and others as well.

I'm just giving some pointers. this is by no means complete information. Check msdn for a complete COM directory and file traversing.

Virii sources have very neat HD traversing :P

Latigo
Posted on 2001-11-02 09:01:51 by latigo
latigo: Yeah i am using the FindFirst FindNext functions, and I am probably gonna stick with these. I have looked at virus sources (I believe the one with good traversal is called Win32.Prizzy) but it was very very optimized and I believe it used Ring0 to do its searches.. :(


beaster: I want to make a program that scans through the directories and files looking for something, but thanx for the help :)


bitRAKE: Yeah i tried to do that :) (emphasize tried!) It just ended up to be one big mess. Basically I map the root dirs, then i choose the first one and map that, and keep doing that until I reach a dead end. But after looking at how messed up the stack was in a debugger, I decided to rewrite the code without this silly recursive routine I had :) Do you know of any sources or anything in assembly that have recursive functions? That would really help out!
Posted on 2001-11-02 19:03:52 by Eagle17
Here is some pseudo code to get you going...
SearchForFiles PROC StartPath:DWORD, match:DWORD

; These change as we recurse that's why they are stored locally
LOCAL WFD:WIN32_FIND_DATA
LOCAL fPathName[MAXPATHLENGTH]
LOCAL hFind:DWORD

; 1. Copy StartPath to fPathName
; 2. Add '\\' on end of path if needed
; 3. Add '*' on end of path
; (path something like 'C:\Dir\*' to get all files & directories)

invoke FindFirstFile, ADDR fPathName, ADDR WFD
mov hFind,eax

.while eax > 0 ; good handle, OR FindNextFile == TRUE

; Create fPathName from path & file name

.if ; Test for file name "." or ".."
; Do Nothing
.elseif ; Test for directory
; This is where the recursion takes place...
invoke SearchForFiles, ADDR fPathName, match
.elseif ; Check if file matches
; Store fPathName string in structure...
.endif

invoke FindNextFile,hFind, ADDR WFD
.endw

invoke FindClose, hFind
ret
SearchForFiles ENDP
Please, post any problems you encounter?

Edit: Also quite a bit of help HERE.
Posted on 2001-11-02 21:27:05 by bitRAKE
Thank you bitRAKE!!! I'll try that as soon as I can.. If I create a working routine, I'll post it up here. Thanks again!
Posted on 2001-11-02 23:15:46 by Eagle17