I'm trying to implement filesystem based file includes for a paper I'm writing and have previously asked a question on this topic. The accepted answer seems to work in the case that I only have a single discovery loop. However, If I try and nest these, it behaves weirdly.
So to replicate some details from the original question:
My filesystem looks like this:
article.tex
sections/
|-- 00-introductions.tex
|-- 10-data.tex
|-- 20-analysis.tex
|-- 90-conclusions.tex
|-- data/
| |-- 00-xxx.tex
| |-- NN-xxx.tex
|
|-- analysis/
|-- 00-xxx.tex
|-- NN-xxx.tex
And my article.tex now looks like:
\documentclass[twocolumn, a4paper]{article}
\input{packages.tex}
\addbibresource{bibliography.bib}
\title{xxx}
\author{xxx}
\date{\today}
\newread\sections
\openin\sections=build/sections.list
\newread\data
\openin\data=build/data.list
\begin{document}
\twocolumn[
\begin{@twocolumnfalse}
\maketitle
\begin{abstract}
{\lipsum[1-2]}
\bigskip
\end{abstract}
\end{@twocolumnfalse}
]
\loop
{\endlinechar=-1 \global\read\sections to \next}
\ifx\next\empty\else
\input{sections/\next}
\repeat
\printbibliography
\end{document}
So, as things stand, this includes all of the files in /sections quite well.
However, I'd also like to include everything in /sections/data into 10-data.tex, so I've added this to the file:
\section{Data}
\loop
{\endlinechar=-1 \global\read\data to \next}
\ifx\next\empty\else
\input{sections/data/\next}
\repeat
However, this results in the introduction and data sections being discovered and all of the subsections in /data/sections but then it stops. For some reason, the outer loop doesn't then seem to add 20-analysis.tex or 90-conclusions.tex to article.tex. The outer loop just seems to stop.
What's going on here? Does LaTex just not support nested loops? Is there a way around this?

build/data.listand opened at the top ofarticle.tex, right below where I do it for sections. It's generated in exactly the same way as sections. The fact that it's including the data sections would imply to me that it's being opened and read just fine – ScottishTapWater Nov 27 '22 at 18:25{\input{sections/\next}}to keep the inner loop local (or use a different loop macro}) – David Carlisle Nov 27 '22 at 18:50