GetFileList
The GetFileList function returns a lua table containing the names of files in a folder. The names are full path names including the full path. The names must match the specified template, which can be simply "*.*".
nFiles = GetFileList( sFolder )
nFiles = GetFileList( sFolder, sTemplate )
nFiles = GetFileList( sFolder, sTemplate, tblNames )
sFolder is the folder to search.
sTemplate is the name pattern to match.
tblNames is a table containing the file names, including the full path.
On success, nFiles > 0 and tblNames contains an array of strings.
On failure, nFiles=0.
This function creates a table that can be parsed using the Lua pairs function, as shown in the example below. The names do no unpack in any "nice" order, like numeric ot alphabetical order. Also see the CFindFiles class for another way to load files from a folder.
This example selects a target folor, then matches all files matching the template "*.*". The files are listed at the end. Note that the entire "for" loop could be replaced by list(tbl) but the latter method does not permit formatting using Printf.
-- fetch the folder |
|
|
|
-- default location |
|
|
-- select folder in GetFolder() |
|
|
|
|
-- find all "*.fts" files in the folder |
|
|
|
-- create a table for the file names |
|
|
-- return the table of file names |
|
|
-- check if no files returned |
|
|
|
|
-- Now extract the names from the table and list them. |
|
|
-- Remember: Lua tables are not in numerical |
|
|
-- or alphabetical order of the keys. |
|
|
|
|
|
|
|
|
|
|
|
Directory Functions, CFindFiles , GetFolder, GetFileName
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics,
Inc. All Rights Reserved.