2

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>
\DTLloaddb{myDB<nr>}{foundfile}
\begin{table}
....
\caption{My table caption (<nr>)}
\end{table}

1 Answer 1

2

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}{%
\DTLloaddb{myDB\x}{fic\x.csv}
\begin{table}
\DTLdisplaydb{myDB\x}
\caption{My table caption (\x)}
\end{table}}{}}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .