flat assembler
Message board for the users of flat assembler.

Index > Windows > find files with subdirectory

Author
Thread Post new topic Reply to topic
pe3epb



Joined: 05 Mar 2011
Posts: 2
pe3epb
hi all,

i found file in directory, but can`t find it in subdirectory

Code:
include 'win32ax.inc'

.data
filemask   db '*',0
updir       db '..',0
FD       WIN32_FIND_DATA

.code
find_first:
  push   ebx
  invoke FindFirstFile,filemask,FD
    cmp    eax,INVALID_HANDLE_VALUE
     je     back
 mov    ebx, eax
output:
      invoke MessageBox,0,FD.cFileName,FD.dwFileAttributes,MB_OK
  test   [FD.dwFileAttributes], FILE_ATTRIBUTE_DIRECTORY
      jnz     find_next
   invoke SetCurrentDirectory, FD.cFileName
    jmp    find_first
find_next:
 invoke FindNextFile,ebx,FD
  test   eax, eax
     jnz    output
       invoke FindClose, ebx
back:
  pop    ebx
  cmp    esp,ebp
      jnb    exit
 invoke SetCurrentDirectory, updir
   jmp    find_next
exit:
       invoke ExitProcess,0
.end find_first    


help me please ...

_________________
Best regards
Post 10 Mar 2011, 08:29
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
You are not checking return values from SetCurrentDirectory, or checking for errors on Find APIs (seems you are always assuming ERROR_FILE_NOT_FOUND). Doing this (aside from being a good practice) could help solving your problem.
Post 10 Mar 2011, 08:51
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
pe3epb



Joined: 05 Mar 2011
Posts: 2
pe3epb
thinks,
i've preferred another way
Code:
include 'win32ax.inc'

.data
buf     rb 500h
filepath   db 'c:\temp',0
allfiles   db '\*.*',0
cudir      db '.',0
updir      db '..',0
wfd    WIN32_FIND_DATA
;hfile  dd ?

.code
start:
        invoke lstrcat, buf, filepath
        invoke lstrcat, buf, allfiles
        call   find_files
        invoke ExitProcess,0

proc    find_files
    locals
        hfile  dd ?
    endl
        invoke FindFirstFile,buf,wfd
        cmp    eax,INVALID_HANDLE_VALUE
        je     exit
        mov    [hfile], eax
check:
        test   [wfd.dwFileAttributes],FILE_ATTRIBUTE_DIRECTORY
        jz     found
        invoke lstrcmp, cudir, wfd.cFileName
        test   eax,eax
        je     next
        invoke lstrcmp, updir, wfd.cFileName
        test   eax,eax
        je     next
        invoke lstrlen, buf
        sub    eax,3
        push   eax
        mov    byte [buf+eax],0
        invoke lstrcat, buf, wfd.cFileName
        invoke lstrlen, buf
        mov    dword [buf+eax],'\*.*'
        mov    byte [buf+eax+4],0
        call   find_files
        pop    eax
        mov    dword [buf+eax-1],'\*.*'
        mov    byte [buf+eax+3],0
        jmp    next
found:
        invoke MessageBox,0,wfd.cFileName,0,MB_OK
next:
        invoke FindNextFile,[hfile],wfd
        test   eax,eax
        jne    check
        invoke FindClose, [hfile]
exit:
        ret
endp
.end start
    


SOLVED

_________________
Best regards
Post 10 Mar 2011, 14:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.