If you have a well defined naming structure, you don't need external scripts which would most likely be OS specific. Programming wise, there is some overhead in this solution, but should work fine for your needs. Might need some adaption as I am not sure where you want to start a new chapter. If the file Section1 in each directory starts with \chapter
, then this is ready to go.
\documentclass{article}
\newcommand*{\MaxNumOfChapters}{10}% Adjust these two settings for your needs.
\newcommand*{\MaxNumOfSections}{6}%
\usepackage{pgffor}%
\begin{document}
\foreach \c in {1,2,...,\MaxNumOfChapters}{%
\foreach \s in {1,2,...,\MaxNumOfSections}{%
\IfFileExists{Chapter\c/Section\s} {%
\input{Chapter\c/Section\s}%
}{%
% files does not exist, so nothing to do
}%
}%
}%
\end{document}
Also note that I assumed that you have no spaces in the directory and file names. You can probably adapt it if you want spaces but I find that is an extra work that I try to avoid.
There are probably a few extra %
here, but I have had problems with extra spaces, and there should be no harm in adding them.