We have a ready-made function returning a file or folder list in one string
/*
typedef struct _WIN32_FIND_DATA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
TCHAR cFileName[MAX_PATH];
TCHAR cAlternateFileName[14];
} WIN32_FIND_DATA, *PWIN32_FIND_DATA, *LPWIN32_FIND_DATA;
*/
'https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx
'selected File Attribute Constants
% FILE_ATTRIBUTE_ARCHIVE 0x20
% FILE_ATTRIBUTE_DEVICE 0x40
% FILE_ATTRIBUTE_DIRECTORY 0x10
% FILE_ATTRIBUTE_HIDDEN 0x2
% FILE_ATTRIBUTE_NORMAL 0x80
% FILE_ATTRIBUTE_READONLY 0x1
% FILE_ATTRIBUTE_SYSTEM 0x4
% FILE_ATTRIBUTE_TEMPORARY 0x100
function GetFileList(string filter, sys*count,optional dirq) as string
======================================================================
'
' sys xyz
'
macro appendList(s,w,i, ls,lw) '(string *s,w, sys *i)
sys ls=len s
sys lw=len w
if i+lw>ls
s+=nuls 1024 '+lw
end if
mid s,i+1,w
i+=lw
end macro
'
WIN32_FIND_DATA f
sys a,e,h,fi
string flist
string cr=chr(13,10)
'
h=FindFirstFile filter, @f
count=0
if h then
do
a=0
if f.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY
if dirq then a=1
if asc(f.cFileName)=46 then a=0 '.' ' ..'
else 'NOT A DIRECTORY
if not dirq then a=1
end if
if a then
count++
appendlist flist, f.cFileName+cr, fi
end if
e=FindNextFile h, @f
if e=0 then
e=GetLastError() 'should be 18 when no more files
exit do
end if
end do
FindClose h
end if
return left (flist,fi)
'
end function
int c
print getFileList "*.txt",c
print "list count " c