Lua:getFileList

From Cheat Engine
Jump to navigation Jump to search

<> Lua API Reference

function getFileList(path, searchMask OPTIONAL, searchSubDirs OPTIONAL, dirAttrib OPTIONAL) : table

Returns an indexed Lua table containing filenames from the specified path.

The optional search mask can be used to limit the result to matching files. Subdirectories can optionally be searched as well.

Function Parameters[edit]

Parameter Type Description
path String The directory path to search in.
searchMask String OPTIONAL The filename mask to search for. For example, "*.txt" or "*.*".
searchSubDirs Boolean OPTIONAL If true, subdirectories are searched as well.
dirAttrib Integer OPTIONAL Optional directory attribute filter.

Returns[edit]

Table — An indexed Lua table containing the matching filenames.

Examples[edit]

List all files in a directory[edit]

1 local files = getFileList([[C:\\Temp]])
2 
3 for i, filename in ipairs(files) do
4   print(filename)
5 end

List files matching a search mask[edit]

1 local files = getFileList([[C:\\Temp]], "*.txt")
2 
3 for i, filename in ipairs(files) do
4   print(filename)
5 end

Search subdirectories[edit]

1 local files = getFileList([[C:\\Temp]], "*.lua", true)
2 
3 for i, filename in ipairs(files) do
4   print(filename)
5 end

Count matching files[edit]

1 local files = getFileList([[C:\\Temp]], "*.CT")
2 
3 print("Found files: " .. tostring(#files))

Use the temporary folder[edit]

1 local tempFolder = getTempFolder()
2 local files = getFileList(tempFolder, "*.*")
3 
4 for i, filename in ipairs(files) do
5   print(filename)
6 end

Filter results in Lua[edit]

1 local files = getFileList([[C:\\Temp]], "*.*")
2 
3 for i, filename in ipairs(files) do
4   if filename:lower():find("%.txt$") then
5     print("Text file: " .. filename)
6   end
7 end

Build full paths from the returned filenames[edit]

1 local path = [[C:\\Temp]]
2 local files = getFileList(path, "*.lua")
3 
4 for i, filename in ipairs(files) do
5   local fullPath = path .. [[\\]] .. filename
6   print(fullPath)
7 end

Guard against an empty result[edit]

1 local files = getFileList([[C:\\Temp]], "*.doesnotexist")
2 
3 if #files == 0 then
4   print("No matching files found")
5 else
6   for i, filename in ipairs(files) do
7     print(filename)
8   end
9 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine