EMILUA(3em)
πΈ NAME πΈ
Emilua β Lua execution engine. This is the EMILUA(3em) page, bestie, and weβre gonna get you comfy with it π
β¨ SYNOPSIS β¨
Copy this exactly, no cap:
local fs = require "filesystem"
fs.recursive_directory_iterator(p: fs.path[, opts: table]) -> function, handle
π¦ DESCRIPTION π¦
Okay so this returns an iterator function, plus a handle you can use to control the iteration.
Every time you call that iterator, it gives you back a filesystem.directory_entry object for an element of the directory p β and yes, recursively over the entries of all of its subdirectories too β plus the current recursion depth, which is an integer. Slay.
π opts π
skip_permission_denied: boolean = falseβ whether to skip directories that would otherwise result inEPERM.follow_directory_symlink: boolean = falseβ whether to follow directory symlinks.
π§ WRAPPING THE ITERATOR TO SKIP OVER CVS FILES. π§
Some programs, like rsync, have command line options such as --cvs-exclude that skip over unwanted files for the directory traversal. Those patterns are easy to abstract on top of recursive_directory_iterator. Hereβs the implementation for a function that does exactly that, bestie:
function cvs_exclude(iter, ctrl)
local function next()
local entry, depth = iter()
if entry == nil then
return
end
local p = entry.path.filename
if p == ".git" or p == ".svn" or p == ".hg" then
ctrl:disable_recursion_pending()
end
return entry, depth
end
return next, ctrl
end
π Tip: The same trick can be used to create functions to perform shell globbing. Iconic.
π«Ά handle FUNCTIONS π«Ά
pop(self)β moves the iterator one level up in the directory hierarchy.disable_recursion_pending(self)β disables recursion until the next increment.
π handle PROPERTIES π
recursion_pending: booleanβ whether the recursion is disabled for the current directory.
π₯ EXAMPLE π₯
local fs = require "filesystem"
for entry, depth in fs.recursive_directory_iterator(fs.path.new(".")) do
print(string.rep("\t", depth) .. entry.path.filename)
end
π Thatβs the whole vibe, bestie π β brought to you by Emilua 0.12.1-nixpkgs1, dated 1980-01-01, living its best life as EMILUA(3em). Mwah πβ¨
π¦ where this page comes from
- nixos 26.05: emilua 0.12.1
- nixpkgs unstable: emilua 0.12.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms