I
think I understood what you want. Let me try to summarize: in the same directory as your main file you have a folder
data
. This folder contains the file
index.txt
and a lot of other files
a.txt
,
b.txt
, ... The names of these other files are written in
index.txt
, one per line. Now you want to loop through the contents of
index.txt
in order to read in (i.e. input) all the other files.
I have a solution that works for this setting:
Code: Select all
\documentclass{article}
\begin{document}
% make @ letter:
\makeatletter
\newread\myread
% file which contains names of other files:
\def\indexfile{data/index.txt}
% open the file:
\openin\myread=\indexfile
% set endlinechar -1 so it isn't saved to \currentfile
% by \readline; a negative value effectively has the same
% effect as if the end of each line were commented out;
% to keep this change local everything is placed in a group:
\begingroup
\endlinechar=-1
% loop until the end of \myread is reached:
\loop\unless\ifeof\myread
\readline\myread to \currentfile% save current line to \currentfile
% now test if \currentfile is empty, if it isn't input the
% corresponding file:
\expandafter\ifx\expandafter\relax\currentfile\relax
\else
\input{data/\currentfile}\par % the \par is just for this example
\fi
\repeat % start again with next line
\endgroup
% close the file again:
\closein\myread
% make @ other again
\makeatother
\end{document}

- file.png (2.71 KiB) Viewed 3377 times
Regards