I would like to be able to input a file by stating only a directory name.
There would be a directory "mydir" containing several tex files, and I would like to be able to type:
\input{mydir}
and have some *.tex file selected and put into my document.
I would like to be able to input a file by stating only a directory name.
There would be a directory "mydir" containing several tex files, and I would like to be able to type:
\input{mydir}
and have some *.tex file selected and put into my document.
You can do that using LuaLaTeX:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{fontspec}
\usepackage{luacode}
\begin{luacode*}
function input_dir(dir)
local p = io.popen('find "./'..dir..'" -type f -name "*.tex"')
for file in p:lines() do
print("Ajout de "..file)
tex.print("\\input{"..file.."}")
end
end
\end{luacode*}
\begin{document}
\directlua{input_dir("mydir")}
\end{document}
Compile it with lualatex --shell-escape yourfile.tex
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(ordiron windows) to get a directory listing to a known file name and then read that with tex to input the files. – David Carlisle Jun 15 '17 at 15:57\InputIfFileExists. For instance naming the filesmyfileN.texwhere 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. – daleif Jun 15 '17 at 16:52