Skip to content

fs.walk ​

Lets you iterate over a path.

Signature ​

luau
function walk(path: string, options: WalkOptions?): () -> string?

Types ​

luau
type WalkOptions = {
    includeDirs: boolean?,
    filter: string?,
}
FieldTypeDescription
includeDirsboolean?If true, directory paths are also yielded. Defaults to false.
filterstring?Glob pattern. Only paths matching the pattern are yielded.

Summary ​

Parameters ​

ParameterTypeDescription
pathstringThe root directory to walk.
optionsWalkOptions?Optional configuration for the walk behavior.

Example ​

luau
local fs = require("@std/fs")

local walk = fs.walk("./data")

while true do
    local path = walk()
    if path == nil then break end
    print(path)
end

Filtering by Pattern ​

luau
local fs = require("@std/fs")

local walk = fs.walk("./src", { filter = "*.luau" })

while true do
    local path = walk()
    if path == nil then break end
    print("Found Luau file:", path)
end