I have a lot of files named by date, e.g., 20151118.tex, 20151117.tex, 20151116.tex, etc. These in a directory separated by month and year (2015/11/20151118.tex).

I would like to input these files without having to have to have the following in my main file:


Is there a way to do this with LaTeX. I would like a clean way to do this, if at all possible.

  • 1
    Generating a file list would be trivial with a combination of (say) ls and sed: ls -R -1 */*/*.tex > filelist.dat, then sed -i 's/^/\\input /' filelist.dat. This lists all .tex files with their paths and prints them to the file filelist.dat; then sed adds \input to each line. Simply take the list and include it in your main .tex file. You could also "do" that in the actual .tex file if you wanted, but I'm not sure I see the advantage....
    – jon
    Nov 19, 2015 at 3:30
  • Related question: Iterating over files in a directory and including them. If you know the range of dates that will need to be included this solution should be adaptable to your case. Nov 19, 2015 at 6:23

1 Answer 1


If you want to incorporate my suggestion above into a single file, this is one approach. The shell commands would need to be different on Windows:


\immediate\write18{ls -R -1 */*/*.tex > filelist.dat}
\immediate\write18{sed -i 's/^/\noexpand\\input /' filelist.dat}%

% For more info, see: http://tex.stackexchange.com/q/25168/8528
        \read\myfile to \mydata
            \mydata\par% <-- note the \par here (may not necessarily be desired)...



  • Thanks, this was what I was looking for. If you are on a Mac, you need to use GNU sed, otherwise the command won't work.
    – chasely
    Nov 19, 2015 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.