\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{a4wide}
\usepackage{listings}
\usepackage{forloop}
\usepackage{ifthen}
\begin{document}

\newcounter{suffix}
\newcounter{dicke}
\newcounter{plm}

\newcommand{\DDir}{}
\newcommand{\DDirP}{}
\newcommand{\Ueberschrift}{}

\section{Inputfile}
\lstinputlisting[breaklines=true]{../lpic/input_thomson24_0.lpi}

\newcommand{\includegraphicsIfExists}[3]{\IfFileExists{../\DDir/Post/#1}
 {
%  \begin{figure}
  \includegraphics[width=\textwidth]{../\DDir/Post/#1} \\[-#2cm]
  \begin{center}
  #3
  \end{center}
%  \end{figure}
 }{}}

\forloop{dicke}{0}{\value{dicke} < 2}
{
 \forloop{plm}{0}{\value{plm} < 2}
 {
  \ifthenelse{\value{dicke}=0}{
   \ifthenelse{\value{plm}=0}{
    \renewcommand{\DDir}{data_thomson24_04_\thesuffix}
    \renewcommand{\DDirP}{data\_thomson24\_04\_\thesuffix}
    \renewcommand{\Ueberschrift}{$d=0,4 \mu m \wedge \Delta t = \thesuffix fs$}
   }{
    \renewcommand{\DDir}{data_thomson24_04_m\thesuffix}
    \renewcommand{\DDirP}{data\_thomson24\_04\_m\thesuffix}
    \renewcommand{\Ueberschrift}{$d=0,4 \mu m \wedge \Delta t = -\thesuffix fs$}
   }
  }{
   \ifthenelse{\value{plm}=0}{
    \renewcommand{\DDir}{data_thomson24_24_\thesuffix}
    \renewcommand{\DDirP}{data\_thomson24\_24\_\thesuffix}
    \renewcommand{\Ueberschrift}{$d=2,4 \mu m \wedge \Delta t = \thesuffix fs$}
   }{
    \renewcommand{\DDir}{data_thomson24_24_m\thesuffix}
    \renewcommand{\DDirP}{data\_thomson24\_24\_m\thesuffix}
    \renewcommand{\Ueberschrift}{$d=2,4 \mu m \wedge \Delta t = -\thesuffix fs$}
   }
  }
  \forloop{suffix}{0}{\value{suffix} < 1000}
  {
   \IfFileExists{../\DDir/times-1}
   {
    \newpage
    \section{\Ueberschrift}

    \includegraphicsIfExists{spacetime-de.pdf}{0}{Elektronendichte}
    \includegraphicsIfExists{spacetime-de_breit.pdf}{0}{Elektronendichte breiter}

    \includegraphicsIfExists{Spektrum_log_p_refl.pdf}{1}{Spektrum\_log\_p-Pol\_refl}
    \includegraphicsIfExists{Feld_p_refl.pdf}{1}{Feld\_p-Pol\_refl}
    \includegraphicsIfExists{Spektrum_log_p_trns.pdf}{1}{Spektrum\_log\_p-Pol\_trns}
    \includegraphicsIfExists{Feld_p_trns.pdf}{1}{Feld\_p-Pol\_trns}

    \includegraphicsIfExists{Spektrum_log_s_refl.pdf}{1}{Spektrum\_log\_s-Pol\_refl}
    \includegraphicsIfExists{Feld_s_refl.pdf}{1}{Feld\_s-Pol\_refl}
    \includegraphicsIfExists{Spektrum_log_s_trns.pdf}{1}{Spektrum\_log\_s-Pol\_trns}
    \includegraphicsIfExists{Feld_s_trns.pdf}{1}{Feld\_s-Pol\_trns}
   }{}
  }
 }
}

\end{document}

