# Create table for each CSV file in a directory

Assume I have a directory which has a dynamic number of files match a certain pattern (e.g. tabledata0.csv, tabledata1.csv). Now I want to create automatically create tables out of it. Sometimes it is 1 table, sometimes 2, etc.

Now for each file matching pattern I want to load the data and create a table. Also I want to track a counter, so.

Is it possible to do the loop with foundfile and nr in the construction below?

Alternatively it is also fine if this cannot be done on pattern but for all files in a directory.

<For each foundfile,nr matching pattern tableData*.csv>
\begin{table}
....
\caption{My table caption (<nr>)}
\end{table}


Here is a solution based on \IfFileExists{}{}{}

\foreach not necessary just to make it easy

\documentclass{article}
\usepackage{datatool}
\usepackage{pgffor}
\begin{document}
\foreach \x in {1,...,10} {%
\IfFileExists{fic\x.csv}{%