Man this is driving me just bonkers.

I must have something wrong in the below snip, but for the life of me I just dont see it. It is supposed to scan the directory and MessageBox every file that matches. However it only picks up the first two and then exits the proc.



ReadInFiles proc
local hMem :dword
local hBuff[MAX_PATH+1] :byte
local w32fd :WIN32_FIND_DATA

jmp StrLabel4
File1 db "c:\*.exe", 0
StrLabel4:

lea ecx, [hBuff]
mov al, 0
mov [ecx], al

; Copy string to hBuff
invoke szCatStr, ADDR hBuff, ADDR File1

; Check path string
invoke MessageBox, 0, ADDR hBuff, 0, MB_OK

invoke FindFirstFile, ADDR hBuff, ADDR w32fd
mov hMem, eax
.if hMem
.while hMem
lea eax, [w32fd.cFileName]
invoke MessageBox, 0, eax, 0, MB_OK
invoke RtlZeroMemory, ADDR w32fd, SIZEOF WIN32_FIND_DATA
invoke FindNextFile, hMem, ADDR w32fd
mov hMem, eax
.endw
.endif

xor eax, eax
ret
ReadInFiles endp


Someone wanna take a quick poke at it?
Thanks!
;)
Posted on 2002-07-16 09:21:57 by Graebel


.data
szPattern db "*.exe", 0
szDone db "Search done!", 0

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

.data?
hFind dd ?
wfd WIN32_FIND_DATA <>


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

.code

start:
invoke FindFirstFile, addr szPattern, addr wfd
mov hFind, eax
cmp eax, INVALID_HANDLE_VALUE ; no file found
je _1
@@:
invoke MessageBox, 0, addr wfd.cFileName, 0, 0 ; show it

invoke FindNextFile, hFind, addr wfd
invoke GetLastError
cmp eax, ERROR_NO_MORE_FILES ; self explaining constant :)
jne @B
_1:
invoke MessageBox, 0, addr szDone, 0, 0
invoke CloseHandle, hFind ; close search handle
call ExitProcess
end start

; #################################################
Posted on 2002-07-16 09:57:10 by bazik


;IN : ptr to a mask like ".exe"
;OUT: EAX = 0 = error
; EAX <> 0 = everythings good....

ReadInFiles proc _mask:DWORD

local hMem :dword
local w32fd :WIN32_FIND_DATA

invoke FindFirstFile, _mask, ADDR w32fd
dec eax
jz _err0

inc eax
mov hMem, eax
_floop: invoke MessageBox,0,addr w32fd.cFileName,0,0

invoke FindNextFile,hMem,addr w32fd
test eax,eax
jnz _floop

invoke FindClose,hMem
_err0: ret
ReadInFiles endp
Posted on 2002-07-16 10:09:18 by mob
damnit bazik :grin: that was really fast
Posted on 2002-07-16 10:11:34 by mob
Thanks bAZiK! (LOL MOB)...

Thanks to the working code it wasnt too hard to figure out that I shouldnt have been reassigning the search handle from FindNextFile (doh). It was messing everything up as (now that I take a closer look at it) it was a bool.

:stupid:
Posted on 2002-07-16 10:19:58 by Graebel

damnit bazik :grin: that was really fast


;)
Posted on 2002-07-16 10:22:40 by bazik