# Inputting files alphabetically

I am creating an anthology of poems and songs, and have a main file where I am using \input to insert separates TeX files which contain the poems.

I was wondering if there was a simpler way of inserting all of the files in alphabetical order based on filename instead of a separate \input for each file?

Could anybody help?

Thank you to for pointing me in the direction of the other questions - they didn't come up when I googled my queries. I am trying to adapt the code in this post but I am getting 2 errors from it. My code is as follows at the moment

\documentclass{minimal}

\makeatletter%
\def \app@exe {\immediate\write18}

\def \inputAllFiles [#1]{%
\app@exe{cmd /c dir /b *.tex > \jobname.tmp}
\InputIfFileExists{\jobname.tmp}{}{}
\AtEndOfDocument{\app@exe{rm -f #1/\jobname.tmp}}}
\makeatother%

\begin{document}

\inputAllFiles{.}

\end{document}


The errors messages I am getting are both on the line with the \inputAllFiles command and say: Use of \inputAllFiles doesn't match its definition and Too many }'s.

I have tried fiddling around with the code, but noting I seem to do helps. Could anybody help to see where I am going wrong?

• – Werner Mar 3 '14 at 23:01
• Welcome to TeX.SE. Related: How to iterate through the name of files in a folder. The accepted answer here is probably already in alphabetical order, but if not it should be easily sorted. – Peter Grill Mar 3 '14 at 23:34
• Why do you add spaces and brackets in the code copied from linked answer? – Paul Gaborit Mar 6 '14 at 22:57
• The original code wasn't being recognised at all, so I looked up the \def command online and that seemed to be the correct syntax. – Nikel King Mar 7 '14 at 22:18