Get number of files in folder

Pure LaTeX: (fileName_1.pdf ... fileName_?.pdf)

\documentclass{article}
\usepackage{animate}
\usepackage{graphicx}

\newcounter{NumFiles}
%\setcounter{NumFiles}{-1} % fileName_0.pdf ... fileName_?.pdf

\newboolean{stop}
\whiledo{\NOT\boolean{stop}}{
  \stepcounter{NumFiles}
  \IfFileExists{./pdfFolder/fileName_\theNumFiles.pdf}{}{
    \addtocounter{NumFiles}{-1}
    \setboolean{stop}{true}
  }
}

\begin{document}
  \animategraphics[controls]{1}{./pdfFolder/fileName_}{1}{\theNumFiles}
\end{document}

Here is an approach with basic Unix commands and \write18{}, listing the contents first and using the wc -l command, saving the output into dummyvar.tex and reading that file to the \numFiles macro.

Of course, the shell-script should be much more failsafe, i.e. store it in a separate file, say countmyfiles.sh and source that file within \write18{source countmyfiles.sh} rather.

\documentclass{article}

\usepackage{animate}


\def\numFiles{-1}

\newread\numfileshandle
\begin{document}
\write18{rm -f dummyvar.tex ; ls -l pdfFolder/fileName_* | wc -l > ./dummyvar.tex}
\immediate\openin\numfileshandle=dummyvar.tex
\read\numfileshandle to \numFiles
\immediate\closein\numfileshandle

There are \numFiles Files

%\animategraphics[controls]{1}{./pdfFolder/fileName_}{1}{\numFiles}
\end{document} 

A test with 20 dummy files within my dummy folder pdfFolder yields 20 as output.