title: How to create a DOS batch file that produces an output file with a list of files specified in the batch arguments?
body: <p>I want to create a batch file <code>batch.bat</code> that can be executed as follows</p>
  
  <pre><code>batch.bat output PDF PNG JPG EPS
  </code></pre>
  
  <p>to produce <code>output.list</code> that contains</p>
  
  <pre><code>filename1.pdf
  filename2.pdf
  filename3.pdf
  filename4.pdf
  filename1.png
  filename2.png
  filename3.jpg
  filename4.eps
  </code></pre>
  
  <p>Note that the first two arguments are the only mandatory arguments. My effort is as follows but I think it uses a barbaric programming technique because <code>%1</code> is used to prepare a new output file and unavoidably it is used again in the first iterate that does nothing.</p>
  
  <pre><code>rem batch.bat
  echo off
  
  rem %1 represents the output file name
  rem the remaining args represent file extension
  
  dir /b *.%1 &gt; %1.list
  
  for %%x in (%*) do (dir /b *.%%x &gt;&gt; %1.list)
  </code></pre>
  
  <p>How to smartly create a DOS batch file that produces an output file with a list of files specified in the batch arguments?</p>
  
  <p>Edit:</p>
  
  <p>I need the batch file because it will be called from the following code.</p>
  
  <pre><code>\documentclass{article}
  \usepackage{graphicx}
  
  \newread\myfile
  \newcount\TotalFiles
  
  \AtBeginDocument
  {
      \immediate\write18{IterateFiles.bat \jobname\space pdf png jpg eps}
      \openin\myfile=\jobname.list\relax
  }
  
  \AtEndDocument
  {
      \closein\myfile
  }
  
  \begin{document}
  \makeatletter
  \loop
      \read\myfile to \mydata
      \unless\ifeof\myfile
      \filename@parse{\mydata}
      \section*{\mydata}
      \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{\filename@base}
      \advance\TotalFiles1\relax
  \repeat
  \makeatother
  
  \section*{Summary}
  There are \the\TotalFiles\ files in total.
  \end{document}
  </code></pre>