LaTeX の For ループを使用して、異なるディレクトリにある複数のファイルを入力する

LaTeX の For ループを使用して、異なるディレクトリにある複数のファイルを入力する
\documentclass{minimal}
\usepackage{chngcntr}
\usepackage{pgffor}
\newcounter{question}
\newcounter{answer}
\setcounter{question}{0}    
\setcounter{answer}{0}
\newcommand\Que[1]{
\stepcounter{question}}
\newcommand\Ans[2][]{
\stepcounter{answer}}
\newcommand\MAX{10}
\begin{document} 
    \foreach \i in {1,...,\MAX} {%
        \edef\File{ques\i}%     The % here are necessary to eliminate any
        \edef\FileName{ans\i}%     The % here are necessary to eliminate any
        \IfFileExists{\FileName}{%  spurious spaces that may get inserted
            \input{\File}%       at these points
            \input{\FileName}%       at these points
        }
    }
\end{document}

これは私のメインの LaTeX ファイルのコードです。他に Question と Answer という 2 つのディレクトリがあります。Question.texディレクトリにはques1、、ques2...という 6 つの質問ファイルがあり、 .texAnswer ディレクトリにはans1、、、ans2... という同じ数のファイルがあります。上記の for ループでディレクトリを指定して、上記のフォルダーからファイルを自動的に取得し、それらを 1 つのフォルダーに保存しなくても済むようにしたいと思います。また、i の値を指定せずに、.texフォルダー内のすべてのファイルを読み取ることができる他の条件を指定できる方法はありますか。

関連情報