Hello,
I have a newbie question. I downloaded Lua code for getting (recursive) list of directory. The slightly modified code looks:
require "lfs"
function dirtree(dir, mask)
assert(dir and dir ~= "", "directory parameter is missing or empty")
if string.sub(dir, -1) == "/" then
dir = string.sub(dir, 1, -2)
end
local function yieldtree(dir)
for entry in lfs.dir(dir) do
if entry ~= "." and entry ~= ".." then
entry = dir .. "/" .. entry
if not mask or string.find(entry, mask) then
coroutine.yield(entry, attr)
end
local attr = lfs.attributes(entry)
if attr.mode == "directory" then yieldtree(entry) end
end
end
end
return coroutine.wrap(function() yieldtree(dir) end)
end
I get "function" for the result of "dirtree":
> a=dirtree(".")
> =type(a)
function
Although I understand the idea of the "dirtree" implementation (I mean I would not be able to program it at the moment, but I understand the majority of steps), I would need to re-implement the function to return "table" (i.e. not "function").
That is, like if I wrote:
> a={"a.txt","b.txt"}
> =type(a)
table
Could you help me please with this?
Thank you in advance.
LuP