FindFiles


The FindFiles function opens a folder and finds all file names matching a file name template. The file names are returned in a Lua table. This function uses the CFindFiles class internally, but does not expose a CFindFiles object to the script.

Syntax

tFileNames = FindFiles( sFolder )

tFileNames = FindFiles( sFolder, sTemplate )

where

    sFolder is the name of the folder to be searched.

    sTemplate is an optional wildcard template for file names to be found

    tFileNames is the returned table containing all the files that were found. On failure, nil is returned.

  

This method returns a Lua table containing all files that were found using the path and file name template. You can iterate over this table using the ipairs iterator as shown in the Example, below, or you can access each file name as a table element, like tFileNames[1] or tFileNames[12]. To get the number of files found, use the table.getn library function, as in table.getn( sFileNames ).

Example

The following script lists all files inside the folder sFolder using the file name template "*.fts"

t = FindFiles( sFolder, "*.fts" )

-- find all the files

if t ~= nil then

-- check if any files were found

  for k,v in ipairs(t) do

-- iterate through the table

    Printf( "%d: %s\r\n", k, v )

-- print the k-th file name

  end

 

end

 

Related Topics

CFindFiles class (class-based file finding)