Skip to content

system.listFiles

since 1.5.0

List files in a directory.

local files = system.listFiles(directory)

Parameters

Name Type Required Description
directory string yes

Returns

files (table of strings)

Examples

-- list .wav files in our sounds folder
for _, name in ipairs(system.listFiles("SCRIPTS:/myscript/sounds") or {}) do
  if name:match("%.wav$") then print(name) end
end

Scanning storage is slow. Do it once (on open, or when the pilot asks) and keep the result, never from wakeup.

Real-world usage

Called 18 times across 6 open-source Ethos Lua projects. A few short excerpts:
local files = system.listFiles(logDir)

src/dashx/app/modules/logs/lib/utils.lua:30

local i18nFiles = system.listFiles("i18n")

gps-qrcode/i18n/i18n.lua:10

local files = system.listFiles(TELEMETRY_DIR) or {}

src/ofs3/lib/logs.lua:219