What's the best way to count all the files in a certain directory? Thanks for any information and happy holidays! :biggrin:
include \masm32\MasmBasic\MasmBasic.inc ; download (http://masm32.com/board/index.php?topic=94.0)
Init
GfNoRecurse=1
GetFiles (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1056) ExpandEnv$("%WinDir%\*")
Inkey Str$("%i files found", eax)
EndOfCode
78 files found
Thank you for your reply! :t I was looking for a "low level" approach using just the Windows api ( your approach is elegant , but I don't like using libraries for everything - I know that's a bad characteristic to have as a programmer - reinventing the wheel and all that :biggrin: ).
You basically do a FindFirst, FindNext pair of loops and store the names in an array.
Ok , thanks! So you basically use the same algorithm to count the files that you would if you wanted to inspect each file in a directory. I thought there might be a way to get the number ahead of time so I could set up space in a data structure to hold information for each file , but I guess not. I suppose you could loop through each file twice , but that would be inefficient. I'll have to use a dynamic data structure and loop through each file once , I suppose. Thanks for the information! :biggrin:
If you are only after the file count OR are not separating file extensions and directories, its only a single loop and its plenty fast enough.