The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on December 28, 2010, 10:17:29 AM

Title: Get files list on a directory
Post by: Farabi on December 28, 2010, 10:17:29 AM
Anyone know how to generate a files list on a directory?
Title: Re: Get files list on a directory
Post by: jj2007 on December 28, 2010, 10:55:45 AM
LB_DIR?
Title: Re: Get files list on a directory
Post by: BogdanOntanu on December 28, 2010, 11:15:15 AM
Use FindFirst / FindNext
Title: Re: Get files list on a directory
Post by: jj2007 on December 28, 2010, 11:40:02 AM
Bogdan, he is an experienced programmer who is brave enough to be lazy. So I offered him the lazy solution :bg
Title: Re: Get files list on a directory
Post by: Farabi on December 28, 2010, 01:38:29 PM
Quote from: jj2007 on December 28, 2010, 11:40:02 AM
Bogdan, he is an experienced programmer who is brave enough to be lazy. So I offered him the lazy solution :bg

Sorry, I did not really understand about recursive one, always wasting my stack  :green
Title: Re: Get files list on a directory
Post by: dedndave on December 28, 2010, 01:49:36 PM
if you just want the files in the current directory - and not the subdirectories - you don't need a recursive routine
still - enumerating files is one of the best applications of recursion - and a good place to learn it   :U

whether you use recursion or not, FindFirst and FindNext are the functions you need
they are pretty easy to use
one of the few things that is almost the same as old DOS programming   :bg
Title: Re: Get files list on a directory
Post by: Vortex on December 28, 2010, 07:15:00 PM
Hi Onan,

Here is a quick example for you :


include     ListFiles.inc

.data

FileName    db '*.*',0
f1          db '%s',13,10,0

.data?

wfd         WIN32_FIND_DATA <?>
hFind       dd ?
buffer      db MAX_PATH + 4 dup(?)

FName       equ OFFSET wfd + WIN32_FIND_DATA.cFileName

.code

start:

    invoke  FindFirstFile,ADDR FileName,ADDR wfd
    cmp     eax,INVALID_HANDLE_VALUE
    je      _exit

    mov     hFind,eax
@@:
    invoke  wsprintf,ADDR buffer,ADDR f1,FName
    invoke  StdOut,ADDR buffer

    invoke  FindNextFile,hFind,ADDR wfd
    test    eax,eax
    jnz     @b

_exit:

    invoke  FindClose,hFind

    invoke  ExitProcess,0

END start
Title: Re: Get files list on a directory
Post by: Farabi on December 29, 2010, 02:48:10 PM
Thaks vortex  :U