Created
April 11, 2022 09:40
-
-
Save Zbizu/04914d3bb2aae0773c9451241be3e004 to your computer and use it in GitHub Desktop.
Lua folder iterator example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------ | |
-- Loader config | |
------------------------------ | |
local mapGeneratorDir = "data/map_generator/" | |
------------------------------ | |
-- loader | |
------------------------------ | |
dofile(mapGeneratorDir .. 'config.lua') | |
local prefix = ">> " | |
local dirCommand = {'find ', ' -maxdepth 1 -type f'} | |
if jit.os == "Windows" then | |
dirCommand = {'dir "', '" /b /aa'} | |
end | |
local folders = {'core', 'resources', 'mods'} | |
local filesCount = 0 | |
for i = 1, #folders do | |
if map_lib_cfg.debugOutput then | |
io.write(prefix .. 'Loading ' .. map_lib_cfg.generatorName .. ' ' .. folders[i] .. '... ') | |
end | |
for dir in io.popen(dirCommand[1] .. mapGeneratorDir .. folders[i] .. '/' .. dirCommand[2]):lines() do | |
filesCount = filesCount + 1 | |
dofile(mapGeneratorDir .. folders[i] .. '/' .. dir) | |
end | |
if map_lib_cfg.debugOutput then | |
print(filesCount .. ' file(s) loaded') | |
end | |
filesCount = 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment