Importing .tex files using \directlua to navigate files and folders
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-... Thanks in advance for your time
On 11 Aug 2022, at 14:08, 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-...
See comment on SX. Don't 'return' the nested call, and it works just fine. function inputAll(dir) for content in lfs.dir(dir) do if ("." ~= content) and (".." ~= content) then fullpath = dir .."/".. content contentType = lfs.attributes(fullpath, "mode") if isTexFile(content, contentType) then tex.sprint(" \\ input{" .. fullpath .. "}") elseif ("directory" == contentType) then -- return inputAll(fullpath) end end end end Best wishes, Taco — Taco Hoekwater E: taco@bittext.nl genderfluid (all pronouns)
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-... Not really a question for this list but anyway ... you can't nest a
On 8/11/2022 2:08 PM, paolo de luca wrote: 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 -----------------------------------------------------------------
participants (3)
-
Hans Hagen
-
paolo de luca
-
Taco Hoekwater