[texhax] list files with lua: windows vs linux

Arno Trautmann Arno.Trautmann at gmx.de
Fri Apr 8 22:22:34 CEST 2016


Hi all,

thanks for the suggestion. I already got a solution by Ulrich in a (by 
accident?) private mail following your ansatz of sorting. For the 
archives, I post the now working code snippet below.

Thanks and best,
Arno

lfs = require "lfs"
tbl = {}
for file in lfs.dir(".") do
   table.insert(tbl, file)
end;

table.sort(tbl, function(a, b)
    return (type(a) == type(b)) and (a < b)	or (type(a) < type(b))
	end
)
for _, file in ipairs(tbl) do
   print(file);
if string.find(file,string.sub(tex.jobname,-7)) then
if string.find(file,".eps") then
if string.find(file,".pdf") then else
tex.print("\\begin{frame}{"..file.."}\\includegraphics[width=12cm]{{{"..string.sub(file,1,-5).."}}}\\end{frame}")
end
end
end
end


On 04/08/2016 08:26 PM, aldus 85 wrote:
> Hi !
>
> I remember having read (and experienced) that we could know about the order in which the for iterator would take things.
> May be a bypass would consist in sorting the list retrieved from the OS.
> May be a lua forum would more adequate to place the question.
>
> Hope this helps.
>
> Aldus
> (mobile)
>
> Aldus
> (mobile)
>> Le 8 avr. 2016 à 15:23, Arno Trautmann <Arno.Trautmann at gmx.de> a écrit :
>>
>> Hi all,
>>
>> I have a data evaluation script that produces eps output files named like
>>
>> scan043_shot001...
>> scan043_shot002...
>> scan043_shot003...
>>
>> I want to have them nicely put together in one pdf, including some additional information. Using some Lua code, I managed to get exactly what I wanted. Under Windows, at least – using:
>>
>> for file in lfs.dir(".") do
>>
>> This results in an iterator that lists the files numerically. Under Linux, however, the file listing is completely arbitrary. Is there a way to influence the order of the output of lfs.dir? The full example is listed below.
>> Is there a (maybe even more elegant) way to get this reliably listing the files independently of the OS?
>>
>> I would be very thankful for any hints!
>>
>> Best,
>> Arno
>>
>> \documentclass{beamer}
>> \setbeamertemplate{navigation symbols}{}
>> \usepackage{graphicx,luacode}
>> \begin{document}
>> \catcode`\_12
>> \begin{luacode}
>> require "lfs"
>> for file in lfs.dir(".") do
>> texio.write_nl(file)
>> if string.find(file,string.sub(tex.jobname,-7)) then
>> if string.find(file,".eps") then
>> if string.find(file,".pdf") then else
>> tex.print("\\begin{frame}{"..file.."}\\includegraphics{{{"..string.sub(file,1,-5).."}}}\\end{frame}")
>> end
>> end
>> end
>> end
>> \end{luacode}
>>
>> \end{document}
>> _______________________________________________
>> TeX FAQ: http://www.tex.ac.uk/faq
>> Mailing list archives: http://tug.org/pipermail/texhax/
>> More links: http://tug.org/begin.html
>>
>> Automated subscription management: http://tug.org/mailman/listinfo/texhax
>> Human mailing list managers: postmaster at tug.org



More information about the texhax mailing list