Hi, how would you get a list of files in a directory using the Win32 API? Which function would be used to do that, sort of like the way the Genesis Emulator Genecyst did.
Here is a fragment from my File Compare program:
Hope this helps... Some credit to Donkey to help work out the 'bumps' ;)
:NaN:
LOCAL find :WIN32_FIND_DATA
...
invoke szCatStr, DirPath, CStr("*.*")
mov TEMPA, $invoke( FindFirstFile, DirPath, addr find )
@@:
lea eax, find.cFileName
mov eax, [eax]
and eax, 0FFh
.if( eax == '.' )
invoke FindNextFile, TEMPA, addr find
.if( !eax )
jmp @EmptyDir
.endif
jmp @B
.endif
xor esi, esi
.while (esi == NULL)
; find == structure with next file info in it (name, etc)
invoke FindNextFile, TEMPA, addr find
.if( ! eax )
inc esi
.endif
.endw
@EmptyDir:
invoke FindClose, TEMPA
Hope this helps... Some credit to Donkey to help work out the 'bumps' ;)
:NaN:
.data
W32FD WIN32_FIND_DATA < 0 >
szPath db "c:\windows\*",0
.code
call FindFirst
jmp ExitProcess
FindFirst: ;
invoke FindFirstFile, addr szPath, addr W32FD ; call API
cmp eax, -1 ;
je NtRet ; Exit
mov esi, eax ; esi->hFindFirstFile
FileOrDir: ;
test W32FD.dwFileAttributes, FILE_ATTRIBUTE_DIRECTORY
jne ProcessFolder ; it is a directory
;ProcessFile: ;
push esi ; save esi
;do something with the file name ;
pop esi ; restore esi
Find_Next: ;
invoke FindNextFile, esi, addr W32FD ; call API
test eax, eax ;
jnz FileOrDir ;
invoke FindClose, esi ; call API
NtRet: ;
ret ; Exit
ProcessFolder: ; Process Directory
cmp W32FD.dwFileAttributes, FILE_ATTRIBUTE_DIRECTORY
jne Find_Next ; we'll skip all hidden, system etc. dirs
cmp byte ptr [W32FD.cFileName], 2Eh ; Check for "." or ".." dir name
jne ProcessDir ;
cmp byte ptr [W32FD.cFileName+1], 0 ;
je Find_Next ; it is ".",0 dir name -> skip it
cmp word ptr [W32FD.cFileName+1], 2Eh ; 2Eh-> "." ASCII code
je Find_Next ; it is "..",0 dir name -> skip it
ProcessDir: ;
push esi ; save esi
;do something with the directory name ;
pop esi ; restore esi
jmp Find_Next ;
How would you know if you have searched through all files in the directory will the function call fail?