title: BATCH FOR-loop but start with specific file
body: <p>I have a number of folders in Windows 10, each of which contains a number of PDF files. For each folder I need to run GhostScript with the folder's PDF files as input but with a certain file as the first one.</p>
  <p>Each folder contains a file named, say, <code>&quot;FirstFile-X.pdf&quot;</code>, where X can be anything, and for each folder I need that file to be the first input.</p>
  <p>I have the following in a batch file:</p>
  <pre class="lang-batch prettyprint-override"><code>setlocal enableDelayedExpansion
  set gs=&quot;C:\Program Files\gs\gs9.54.0\bin\gswin64.exe&quot;
  set options=-dNOPAUSE -q -dBATCH -sDEVICE=pdfwrite
  %gs% -sDEFAULTPAPERSIZE=a4 -dBATCH
  for /d %%d in (*) do (
      set a=
      set output=%%d.pdf
      for %%f in (%%d\*.pdf) do (
          set &quot;a=!a!%%d^\%%~nxf &quot;
      )
      %gs% %options% -sOutputFile=!output! !a!
  )
  </code></pre>
  <p>The above code works but it doesn't take that specific file as the first input. Is it possible to have the innermost <code>for-loop</code> run through each file in the order that I need?</p>