Skip to content

Instantly share code, notes, and snippets.

@SkyyySi
Created February 24, 2025 12:04
local lfs = require("lfs")
local _M = {}
function _M.list_child_files(directory_path)
local function get_full_child_paths(child_name)
if (child_name == ".") or (child_name == "..") then
return {}
end
local child_path = directory_path .. "/" .. child_name
local child_attributes = lfs.attributes(child_path)
if type(child_attributes) ~= "table" then
return {}
end
if child_attributes.mode == "directory" then
return list_child_files(child_path)
end
return { child_path }
end
local result = {}
for child in lfs.dir(directory_path) do
local child_paths = get_full_child_paths(child)
for i = 1, #child_paths do
table.insert(result, child_paths[i])
end
end
return result
end
function _M.import_all_modules_in_directory(directory_path)
for _, path in ipairs(_M.list_child_files(directory_path)) do
dofile(path)
end
end
return _M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment