kryton9
21-03-2007, 00:53
Guys, I was studying some of the code that Petr has put into Topdown3D and ran across this function he created. I think many will find it very handy as it is very powerful and a good example of a very neat thinBasic command.
function GetFileList( path as string, mask as string ) as string
local FileNames as string
LOCAL pList AS LONG
LOCAL nItems AS LONG
local i as long
pList = DIR_List(path, mask, %FILE_NORMAL OR %FILE_HIDDEN OR %FILE_SYSTEM OR %FILE_ADDPATH)
nItems = LL_Count(pList)
for i = 1 to nItems
FileNames += LL_GetItem(pList, i )+","
next
FileNames = Rtrim$(FileNames, ",")
LL_Free(pList)
function = FileNames
end function
It would be called for example to get all bmp files in a textures folder, then to randomly select one from the list:
local BackgroundBMP as string = GetFileList(APP_SOURCEPATH + dirTextures+"\instant action level 01\", "ia*.bmp")
msgbox(0,BackgroundBMP)
BackgroundBMP = parse$(BackgroundBMP, ",", rnd(1, parsecount(BackgroundBMP, ",")))
Petr, this routine is really nice, thanks I would never have figured out how to use it otherwise!!
function GetFileList( path as string, mask as string ) as string
local FileNames as string
LOCAL pList AS LONG
LOCAL nItems AS LONG
local i as long
pList = DIR_List(path, mask, %FILE_NORMAL OR %FILE_HIDDEN OR %FILE_SYSTEM OR %FILE_ADDPATH)
nItems = LL_Count(pList)
for i = 1 to nItems
FileNames += LL_GetItem(pList, i )+","
next
FileNames = Rtrim$(FileNames, ",")
LL_Free(pList)
function = FileNames
end function
It would be called for example to get all bmp files in a textures folder, then to randomly select one from the list:
local BackgroundBMP as string = GetFileList(APP_SOURCEPATH + dirTextures+"\instant action level 01\", "ia*.bmp")
msgbox(0,BackgroundBMP)
BackgroundBMP = parse$(BackgroundBMP, ",", rnd(1, parsecount(BackgroundBMP, ",")))
Petr, this routine is really nice, thanks I would never have figured out how to use it otherwise!!