I am using the function given in this answer https://tex.stackexchange.com/a/7657/110509 (with a minor alteration of ls #1/*.tex to ls #1/*/*.tex #1/*.tex so files in subdirectories also get included).
However if I run
latex -shell-escape -interaction=nonstopmode Master.tex
pdflatex -shell-escape -interaction=nonstopmode Master.tex
My file Master.dvi has no content table but the file Master.pdf has all the files included by the above function doubled (i.e. they all appear twice in the document). Every other combination of latex and pdflatex I have tried, with and without -shell-escape gives either no table of context, or files appearing more then once.
Does anyone know, firstly why this is happening? and secondly how I can get around it?
It seems to me that the function is running every time I compile it.
Edit
I have now had chance to play around with an example. Here is my Master.tex file:
\documentclass[a4paper,16pt]{article}
\makeatletter
\def\app@exe{\immediate\write18}
\def\inputAllFiles#1{%
\app@exe{ls #1/*/*.tex #1/*.tex | xargs cat >> \jobname.tmp}%
\InputIfFileExists{\jobname.tmp}{}
\AtEndDocument{\app@exe{rm -f #1/\jobname.tmp}}}
\makeatother
\begin{document}
\title{Test}
\date{\today}
\maketitle
\newpage
\tableofcontents
\newpage
\inputAllFiles{/home/user/My_answers/Test/Main1/}
\inputAllFiles{/home/user/My_answers/Test/Main2/}
\end{document}
Where in the directory .../Main1/ I have ./Min1_1/File1_1.tex and ./Min1_2/File1_2.tex and in .../Main2/ I have ./Min2_1/File2_1.tex and ./Min2_2/File2_1.tex. The code in each of the e.g. File1_1.tex documents is very simple e.g.
\section{File 1.1}
Hi
\subsection{subsection 1}
Interestingly the code works fine if I comment out one of the \inputAllFiles functions and it seems to be the fact that I am using two (or more) of them that is causing the problems.
ls #1*.texdoes not occur in the answer you linked to so it is not at all obvious what code you are actually running. Also, be sure to read the comments. The code in the answer definitely has bugs. – cfr Jul 28 '16 at 12:49rmcommand tries to delete an unknown file (in#1directory). Try withrm -f \jobname.tmp... – Paul Gaborit Jul 30 '16 at 10:10