You could try texosquery
if you have Java installed.
Example (where the sub-directory is called subdir
):
\documentclass{article}
\usepackage{texosquery}
\makeatletter
% \inputfiles{dir}
\newcommand*{\inputfiles}[1]{%
\TeXOSQueryRegularFileList{\result}{,}{#1}%
\ifx\result\empty
Query failed!
\else
\@for\thisfile:=\result\do{\input{#1/\thisfile}}%
\fi
}
\makeatother
\begin{document}
\inputfiles{subdir}
\end{document}
That will input all regular files in the subdirectory. Alternatively you could apply a filter:
\documentclass{article}
\usepackage{texosquery}
\makeatletter
% \inputfiles{dir}
\newcommand*{\inputfiles}[1]{%
\TeXOSQueryFilterFileList{\result}{,}{.+\string\.tex}{#1}%
\ifx\result\empty
Query failed!
\else
\@for\thisfile:=\result\do{\input{#1/\thisfile}}%
\fi
}
\makeatother
\begin{document}
\inputfiles{subdir}
\end{document}
This will only match files ending with .tex
.
Note: texosquery
may require some setting up before first use. There should be a file called texosquery.cfg
in your TeX distribution, which contains instructions on how to set it up. It will need editing if you have Java 8 (especially if you want to use it with the restricted shell escape) or if you have Java 5 or 6. The default is set up for Java 7 and unrestricted mode only.
ls
(ordir
on windows) to get a directory listing to a known file name and then read that with tex to input the files.\InputIfFileExists
. For instance naming the filesmyfileN.tex
where N is a number, and knowing an upper limit to the number of files makes it easy to incluse also of those using a loop.