News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Put files and folders into a string array

Started by jj2007, October 24, 2021, 09:48:36 AM

Previous topic - Next topic

jj2007

MasmBasic features GetFiles and Getfolders; but how to get both files and folders? Here is a snippet that demonstrates the use of AddFolders:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  PrintLine cfm$("size\tdate        time\tfilename")
  GetFiles "\Masm32\Examples\unicode_generic\*.inc|*.asm"
  AddFolders "\Masm32\Examples\unicode_generic"
  SortFiles date, asc           ; sort by date, ascending (oldest first); returns #files
  For_ ecx=0 To eax-1           ; print the results
       PrintLine Str$(GfSize(ecx)), Tb$, GfDate$(ecx), Spc2$, GfTime$(ecx), Tb$, Files$(ecx)
  Next
  Inkey Str$("\n%i files and folders found", Files$(?))
EndOfCode


Output (may slightly differ on your machine):
size    date        time        filename
365     07.10.2011  15:04:22    \Masm32\Examples\unicode_generic\multi_lingual\multi_lingual.inc
828     14.10.2011  14:16:32    \Masm32\Examples\unicode_generic\console\hello\hello.asm
5879    15.10.2011  10:05:39    \Masm32\Examples\unicode_generic\template\template.inc
1637    18.10.2011  01:14:04    \Masm32\Examples\unicode_generic\string_examples\append$\append$.asm
1141    18.10.2011  08:10:02    \Masm32\Examples\unicode_generic\string_examples\find$\find$.asm
1566    18.10.2011  14:41:15    \Masm32\Examples\unicode_generic\string_examples\cat$\cat$.asm
1791    18.10.2011  14:47:26    \Masm32\Examples\unicode_generic\string_examples\switch$\switch$.asm
1222    18.10.2011  14:51:19    \Masm32\Examples\unicode_generic\diskfile\diskfile.asm
5372    18.10.2011  15:28:15    \Masm32\Examples\unicode_generic\multi_lingual\multi_lingual.asm
1174    18.10.2011  15:34:25    \Masm32\Examples\unicode_generic\console\textio\textio.asm
893099  12.11.2011  08:04:41    \Masm32\Examples\unicode_generic\diskfile\WININC.INC
0       30.10.2014  23:13:45    \Masm32\Examples\unicode_generic\console
0       30.10.2014  23:13:45    \Masm32\Examples\unicode_generic\string_examples
11863   19.09.2018  19:11:19    \Masm32\Examples\unicode_generic\template\template.asm
8215    19.09.2018  19:19:14    \Masm32\Examples\unicode_generic\template\misc.asm
0       22.09.2018  12:13:45    \Masm32\Examples\unicode_generic\template
0       22.09.2018  12:13:55    \Masm32\Examples\unicode_generic\console\textio
0       22.09.2018  12:13:56    \Masm32\Examples\unicode_generic\multi_lingual
0       22.09.2018  12:13:57    \Masm32\Examples\unicode_generic\diskfile
0       22.09.2018  12:13:58    \Masm32\Examples\unicode_generic\string_examples\switch$
0       22.09.2018  12:13:58    \Masm32\Examples\unicode_generic\string_examples\cat$
0       22.09.2018  12:13:58    \Masm32\Examples\unicode_generic\string_examples\find$
0       22.09.2018  12:13:59    \Masm32\Examples\unicode_generic\string_examples\append$
0       22.09.2018  12:13:59    \Masm32\Examples\unicode_generic\console\hello

24 files and folders found


In the Files$() array, files and folders are treated identically. Most folders are at the end of this listing sorted by date, because they got created after the files; their size is 0 bytes, and they don't have file extensions.