【asm】遍历目录以及子目录所有文件 - 非递归
本帖最后由 Ayala 于 2017-7-3 19:25 编辑fdata struc
h dword ?
n dword ?
k dword ?
fdata ends
llist struc
_nextdword ?
_lastdword ?
_datafdata <>
llist ends
.code
Dirtrav proc uses esi edi ebx fdir,fcallback,fcontext
LOCAL fd1:WIN32_FIND_DATA
LOCAL dp:llist
LOCAL dir:word
LOCAL curDir:word
lea edi,fd1
assume edi:ptr WIN32_FIND_DATA
invoke GetCurrentDirectory,MAX_PATH,addr curDir
mov ebx,fdir
invoke SetCurrentDirectory,ebx
invoke FindFirstFile,$CTA0(".\\*"),edi
lea ebx,dp
assume ebx:ptr llist
mov ._next,0
mov ._last,0
mov ._data.h,eax
.while ._data.h!=INVALID_HANDLE_VALUE
mov esi,._data.h
mov eax,fcallback
.if eax
PROTO@8 TYPEDEF PROTO STDCALL :DWORD,:DWORD
invoke (PROTO@8 ptr eax),edi,fcontext
.break .if eax
.endif
mov eax,dword ptr .cFileName
and eax,0FFFFFFh
.if .dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY && eax!=".." && ax!="."
invoke crt_malloc,sizeof dp
.if !eax
jmp done
.endif
assume eax:ptr llist
mov ._next,0
mov ._last,ebx
mov ._next,eax
mov ebx,eax
assume eax:ptr nothing
invoke SetCurrentDirectory,addr .cFileName
invoke FindFirstFile,$CTA0(".\\*"),edi
mov ._data.h,eax
.else
invoke FindNextFile,esi,edi
.if !eax
invoke FindClose,esi
mov ebx,._last
.break .if !ebx
invoke crt_free,._next
;invoke crt_system,$CTA0("PAUSE")
invoke SetCurrentDirectory,$CTA0("..\\")
.endif
.endif
.endw
done:
.while ebx
invoke crt_free,._next
mov ebx,._last
.endw
invoke SetCurrentDirectory,addr curDir
assume edi:nothing
xor eax,eax
ret
Dirtrav endp
:P:P:P:P:P:P:P
页:
[1]