I have a folder called diary
which contains a series of files:
20120101.tex
20120105.tex
20120304.tex
- etc.
How can I create a single LaTeX document that includes each of these files, in alphabetical order? I'd like to do this within LaTeX, not using LuaTeX or shell operations (to make it portable).
I found a near-solution here, but I can't get it to work properly for this situation.
\documentclass{book}
\usepackage{xifthen}
\begin{document}
% 20120101.tex included here
% 20120105.tex included here
% etc
\end{document}
The code from the near solution linked above for iterating over files that I am trying to modify is:
\foreach \Year in {\StartYear,...,\EndYear}
{ \foreach \Month in {Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}
{ \foreach \Day in {1,...,31}
{ \IfFileExists{\Year/\Month/\Day}
{ \newread\mysource
\openin\mysource=\Year/\Month/\Day.tex
\read\mysource to \firstline
\closein\mysource
\xdef\writetitle{1}
\begin{loggentry}{\Year - \Month - \Day}{\firstline}
\xdef\writetitle{0}
\input{\Year/\Month/\Day}
\end{loggentry}
}
{ % files does not exist, so nothing to do
}
}
}
}
Here is my failed modification that I want to not look in year/month subdirectories, but read the files as I have listed them above:
\foreach \Year in {\StartYear,...,\EndYear}
{ \foreach \Month in {01,02,03,04,05,06,07,08,09,10,11,12}
{ \foreach \Day in {01,...,31}
{ \IfFileExists{{Year}{Month}{Day}}
{ \newread\mysource
\openin\mysource={Year}{Month}{Day}.tex
\read\mysource to \firstline
\closein\mysource
\xdef\writetitle{1}
\begin{loggentry}{\Year - \Month - \Day}{\firstline}
\xdef\writetitle{0}
\input{{YearMonth/\Day}
\end{loggentry}
}
{ % files does not exist, so nothing to do
}
}
}
}
The problem is in concatenating the variables to create the file name instead of subdirectories, which I can't figure out how to do (the above, obviously, doesn't work).
Best Answer
Here is an adaption of my earlier answer from How to iterate through the name of files in a folder:
Notes:
YYYYMMDD.tex
.\input
.\MinYear
\MaxYear
to suit.standalone
package. If your dairy entries are quite small this may not be of much value, but if they are lengthy this would be useful as you can view each day as you go and ensure that everything typesets properly and then simply run the main program at certain intervals.One reason why your attempt failed is that the code
\foreach \Day in {01,...,31}
yields the sequence:So while the first day is correct the subsequent days 2-9 are not two digits.
References:
Code: