On 8/11/2022 2:08 PM, paolo de luca wrote:
Hi all,

I've been trying to import all tex files and inside a given folder, the
issue I'm facing is that my lua call is not able to navigate folders: it
only works for files.
It's worth mentioning that compilation successfully completes as the
document is created, but I have no errors explaining me why it's not
working as intended.
I've also opened a question on tex.stackexchange.

would you mind having a look at it ?

https://tex.stackexchange.com/questions/653499/understanding-implicit-error-on-a-recursive-function
Not really a question for this list but anyway ... you can't nest a dirctory scan (has to do with states and handles outside our scope) so you need to collect. I patched your code:

function inputAll(dir)
    local allFiles = { }
    local allDirs = { }
    local function isTexFile(dirOrFolder)
        return string.find(dirOrFolder, ".+%.tex")
    end
    local function collectSome(m)
        for content in lfs.dir(m) do
            if ("." ~= content) and (".." ~= content)  then
                local fullpath = m .."/".. content
                local contentType = lfs.attributes(fullpath, "mode")
                if contentType == "file" then
                    if isTexFile(content) then
                        table.insert(allFiles, fullpath)
                    end
                elseif contentType == "directory" then
                    table.insert(allDirs, fullpath)
                    collectSome(fullpath)
                end
            end
        end
    end
    collectSome(dir)
    for i, name in ipairs(allDirs) do
        collectSome(name)
    end
    table.sort(allFiles)
    for i, name in ipairs(allFiles) do
        print(name)
    end
end

or something like that (warning for context users: we have better ways than this)

Hans


-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
_______________________________________________
dev-luatex mailing list
dev-luatex@ntg.nl
https://mailman.ntg.nl/mailman/listinfo/dev-luatex

Reply via email to