having trouble with moving into directories while searching for files
anyone think of a better way to search for certain file extentions?
or know why the code is failing

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib
FindMe     PROTO :DWORD,:DWORD
.data
AppName        db 'MP3 Lister',0
TheString      db '*',0
TheExtention  db '*.mp3',0
FileCaption    db "The File's Name Is...",0 ;"
FolderCaption  db "Found a folder , going in :)",0 ;"
dirback        db "..",0

.data?
fd            WIN32_FIND_DATA <>
buffer        db 256 dup(?)

.code
start:
        invoke GetLogicalDriveStrings, 100,addr buffer ;get the current drives attached to system
        mov edi,offset buffer                          ;copy it into edi
DriveLoop: 
        invoke GetDriveType, edi                      ;get the drive type
        cmp eax, DRIVE_FIXED                          ; see if its a HDD or cdROM Drive                     
        jnz NextDrive                                  ;if not a fixed drive then check the next drive
        invoke MessageBox,0,edi,addr AppName,0        ;show the current Drive you're scanning 
        invoke FindMe,edi,addR TheString              ;start scanning it bitch
NextDrive:
        add edi, 4
        cmp byte ptr [ edi ], 0                        ;last drive on the list?
        jnz  DriveLoop                                ;if not get some more bitch
invoke ExitProcess,NULL                                ;else get out fuck out of town


FindMe proc  Path :DWORD, filter :DWORD
  LOCAL PathName[256]:byte  ;buffer to hold the current path
  LOCAL buffer1[256]:byte
  LOCAL hFind    :DWORD    ;file pointer to the current file
                                         
              invoke lstrcpy, addR PathName, Path    ; put initial dir to PathName
              invoke lstrcat, addR PathName, filter  ; add * wildcard to PathName
              invoke FindFirstFile, addr PathName, addr fd       
              mov hFind, eax
 
  .while eax > 0                                                      ; look for '.'
          cmp  byte ptr ,"."                              ; if '.'found skip them 
          jz nextf
          test fd.dwFileAttributes, FILE_ATTRIBUTE_DIRECTORY            ; check if its a dir
          jz itsafile                                                  ;if not then jump to the file proc
            invoke MessageBox,0,addr fd.cFileName,addr FolderCaption,0   
            invoke SetCurrentDirectory,addr fd.cFileName              ; if so set as current dir
            invoke GetCurrentDirectory,sizeof buffer1, addR buffer1    ; save full dir name into buffer 
            invoke FindMe,addR buffer1, filter                        ; recursive call
            invoke SetCurrentDirectory, addR dirback                  ; go back
            jmp nextf
itsafile:                 
            ; its a file :)
            ;;;;;do file extension check here;;;;;;;                                                 
            ;invoke lstrcmp,addr filename,fd.cFileName
            invoke MessageBox,0,addr fd.cFileName,addr FileCaption,0           
nextf:     
            invoke FindNextFile, hFind, addr fd              ; next
  .endw
            invoke FindClose,hFind
          ret         
FindMe endp
end start
Posted on 2005-05-28 21:19:11 by illwill
A couple of quick notes before I pop off for bed: your buffers are too small. You need to use MAX_PATH+1 instead of 256, otherwise you can get bitten pretty hard by the buffer overflow beast. Also, the lstr* functions are pretty unsafe... and since you change current directory, you should save+restore the original directory (but you can do some string concatenation instead, and avoid changing directory).
Posted on 2005-05-29 19:59:37 by f0dder
:D
http://www.asmcommunity.net/board/index.php?topic=14133.0

Regards,
Lingo
Posted on 2005-05-30 05:55:53 by lingo12