Hello ?? sorry but I am spanish and my english is not good.

I am learning for recursive functions and try make a function
for find all files in a directory with all subfolders included.

I have MASM32 v7 and here yu can see my code below

what I have to do bad? how is the correct secuence?

Thanke you for your help. ( I am happy with MASM32 )

; ########################################################################

; ***** I call from here and asterix is == db "*.*",0 ******

; ***** lea eax, asterix ******
; ***** invoke ForFind, hWnd, eax ******


ForFind proc HWnd :DWORD, search :DWORD


; ********* FIND FOR FILES FIRST ************


invoke FindFirstFile, search, offset fnd ;search == *.*
mov hwndff,eax

nextf: lea esi,fnd.cFileName ; Skip "." and ".."
cmp ,byte ptr "."
je nofile

cmp fnd.dwFileAttributes ,FILE_ATTRIBUTE_DIRECTORY ;skip directorys
je nofile

invoke MessageBox, HWnd, addr fnd.cFileName, ADDR caption, MB_OK ;show filename

nofile: invoke FindNextFile,hwndff,offset fnd
cmp eax, 0
jne nextf


; ********** FIND FOR DIRECTORYS **************


invoke FindFirstFile, addr asterix, offset fnd ; asterix == *.*
mov hwndff,eax

nextdir: lea esi,fnd.cFileName
cmp ,byte ptr "." ; Skip "." and ".."
je isnotadir

cmp fnd.dwFileAttributes ,FILE_ATTRIBUTE_DIRECTORY ; skip files
jne isnotadir

szText dir, " Esto es un directorio " ;show selected directory
invoke MessageBox,HWnd,addr fnd.cFileName,ADDR dir,MB_OK

invoke SetCurrentDirectory, ADDR fnd.cFileName

invoke ForFind, HWnd, search ;recursive call ???

invoke SetCurrentDirectory,ADDR dirback ; go back a directory

invoke GetCurrentDirectory, 260, ADDR buffer1 ; show current directory
invoke MessageBox,HWnd,addr buffer1,ADDR caption,MB_OK


isnotadir: invoke FindNextFile,hwndff,offset fnd
cmp eax, 0
jne nextdir


ret

ForFind endp

; ########################################################################

Saludos cordiales desde Barcelona :confused: :alright:
Posted on 2002-06-01 07:27:46 by mnemox
mnemox, welcome to the board!

To do recursive you need to save the state of the function before executing that function again - else when you return, you do not start where you were.
invoke SetCurrentDirectory,ADDR dirback ; go back a directory
After this function, you start over looking through previous directory and find the first directory you just displayed! Look at this post ( HERE ). Complete example ( HERE ).
Posted on 2002-06-01 08:49:53 by bitRAKE
Ok, I try it tomorrow another time thanke you very much...
Posted on 2002-06-01 16:39:48 by mnemox
the routine are working good :alright:

Here is the code for everyone

; ########################################################################

; This little routine show in a messagebox all names of files and directories
; included in a initial directory. Thanks to bitRAKE for orientation


ForFind proc HWnd :DWORD, Path :DWORD, match :DWORD

LOCAL PathName[260]
LOCAL fnd :WIN32_FIND_DATA
LOCAL hFind :DWORD

invoke lstrcpy, ADDR PathName, Path ; initial directory to PathName
invoke lstrcat, ADDR PathName, match ; add \*.* to PathName

invoke FindFirstFile, addr PathName, addr fnd
mov hFind,eax

.while eax > 0

lea esi,fnd.cFileName ; Skip "." and ".."
cmp ,byte ptr "."
je nextf

.if fnd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY

invoke SetCurrentDirectory, ADDR fnd.cFileName ; into dir

invoke GetCurrentDirectory, 260, ADDR buffer1

invoke MessageBox,HWnd,addr buffer1,ADDR caption,MB_OK ; show Current directory

invoke ForFind, HWnd, ADDR buffer1, match ; recursive call

invoke SetCurrentDirectory,ADDR dirback ; go back

.else

invoke MessageBox,HWnd,addr fnd.cFileName,ADDR caption,MB_OK ; show Current fileName

.endif

nextf: invoke FindNextFile,hFind,addr fnd ; next

.endw


ret

ForFind endp

; ########################################################################
Posted on 2002-06-02 10:26:32 by mnemox