title: Batch script to Get First Filename from a directory
body: <p>My function needs the first filename from a particular directory to process some tests using the first file, on completing tests delete first file from directory<BR></p>
  
  <p>I tried as below <BR></p>
  
  <pre><code>FOR /R \\&lt;My Folder&gt; %F in (*.zip*) do echo ~nF  &gt;%test_list%
  set /p firstline=%test_list%
  echo %firstline% 
  
  
  FOR /F "tokens=*" %%A IN ('dir %test_firmware_dir% /b/s ^| find /c ".zip"') DO SET 
   count=%%A
    echo %count%
   :test_execution
    if %count% NEQ 0 (
    echo ON
    dir /b %test_firmware_dir%\*.zip &gt;%test_firmware_list%
   set /p firstline=&lt;%test_firmware_list%
   set /a filename=%firstline:~0,-4%
    Echo %filename%
    Echo *********************************************************
   Echo "Now running batch queue tests with %filename%"
    Echo ********************************************************
  </code></pre>
  
  <p>it is showing last element any procedure to get first element ??</p>