If you have Java installed, you can use texosquery with TeX's piped shell escape. The follow assumes all your image files have the extensions .png:
\documentclass{article}
\usepackage{graphicx,caption}
\usepackage{texosquery}% requires piped shell escape
\makeatletter
% syntax: \foreachfile{cs}{pattern}{folder}{body}
\newcommand{\foreachfile}[4]{%
\TeXOSQueryFilterFileList{\result}{,}{#2}{#3}%
\ifx\result\empty
Query failed!
\else
\@for#1:=\result\do{#4}%
\fi
}
\makeatother
\begin{document}
\foreachfile{\thisimage}{.*\string\.png}{figures}
{
\begin{figure}[!htb]
\edef\x{\noexpand\includegraphics[scale=1]{figures/\thisimage}}\x
\caption{\thisimage}
\end{figure}
}
\end{document}
This requires the shell escape enabled. For example:
pdflatex -shell-escape mydoc
(where the file is called mydoc.tex). If you use MiKTeX you also need to use --enable-pipes. If you use LuaTeX with texosquery v1.3 or below, you'll also need to switch off the dry run mode manually with \TeXOSQueryDryRunfalse. This isn't needed for v1.4.
texosquery needs a bit of setting up before use. There should be a configuration file called texosquery.cfg which can be found with
kpsewhich texosquery.cfg
(run from the command line). It's best to copy this file to your TEXMFLOCAL or TEXMFHOME tree to prevent your changes from being overwritten whenever the package is upgraded.
Find out which version of Java you have. (I'm guessing from your comment that you have Java 5.) The version number can be found with
java -version
For example, for me this displays java version "1.8.0_92" which means Java 8.
If you have Java 5 or 6, the texosquery.cfg file needs to contain the line
\def\TeXOSInvokerName{texosquery-jre5}
The line with \TeXOSQueryAllowRestricted must be commented out.
If you have Java 7, the texosquery.cfg file needs to contain the line
\def\TeXOSInvokerName{texosquery}
and, again, the line with \TeXOSQueryAllowRestricted must be commented out. This is the default configuration.
If you have Java 8, the texosquery.cfg file needs to contain the line
\def\TeXOSInvokerName{texosquery-jre8}
This form of the application has been added to restricted list for TeX Live 2017, so if you have TL2017, you can uncomment \TeXOSQueryAllowRestricted otherwise it needs to remain commented out.
Only the Java 8 version (texosquery-jre8) was evaluated for the restricted list as older versions of Java are considered a security risk.
Note: with texosquery v1.3 and below, you can't use \TeXOSQueryFilterFileList in restricted mode (but it will work with the unrestricted shell escape). Version 1.4 allows it, but with limitations imposed by the security features of the restricted mode.