title: Windows batch script - issue with moving files from a directory in a for loop
body: <p>I have come across an strange issue that puzzles me at the moment -</p>
  
  <p>The windows script I am running is a wrapper script that will loop through all the csv files from a public directory and will move them to a processing folder before I call one of the sub-processes. The wrapper script is supposed to terminate when there is no more csv files left in the input folder. However I am getting a message saying </p>
  
  <blockquote>
    <p>'A duplicate file name exists, or the file
    cannot be found.'</p>
  </blockquote>
  
  <p>The input folder \abcinc.lcl\utility\aaa sits as an empty folder with no other files or sub-folders under it. </p>
  
  <p>Any reasons why the following for loop is not terminating normally upon no files and failing instead?</p>
  
  <blockquote>
    <p>for /F %%i in ('dir /b "\abcinc.lcl\utility\aaa*.csv"') do (</p>
  </blockquote>
  
  <p>Here is the full code snippet along with the output from the log -</p>
  
  <pre><code>***************************************************************************
  ****    Wrapper Script                                                 ****
  ***************************************************************************
  
  @echo off
  Setlocal enabledelayedexpansion
  
  for /F %%i in ('dir /b "\\abcinc.lcl\utility\aaa\*.csv"') do (
     echo Folder is NON empty
          move "\\abcinc.lcl\utility\aaa\*.csv" E:\abc\INFILES
      For %%a in (E:\abc\INFILES\*.csv) Do (
          PING 10.1.41.19 -n 5 &gt;NUL
          Set "File=LOADIN.csv"
          Ren "%%a" "!File!"
          CALL "E:\abc\scripts\RUNALL.BAT"
          PING 10.1.41.19 -n 5 &gt;NUL
          MOVE "E:\abc\INFILES\LOADIN.CSV" "E:\abc\INFILES\ARCHIVE\LOADIN - %DATE:/=-% %TIME::=-%.CSV"
      PING 10.2.23.49 -n 3 &gt;NUL
          MOVE "\\abcinc.lcl\utility\aaa\OUTPUT\outfile.csv" "\\abcinc.lcl\utility\aaa\OUTPUT\ARCHIVE\outfile - %DATE:/=-% %TIME::=-%.CSV"
  
                               )
  
          )
  
  EXIT
  
  ***********************************************************************
  ****    LOG OUTPUT                                                 ****
  ***********************************************************************
  
  
  Folder is NON empty
  \\abcinc.lcl\utility\aaa\File1.csv
  \\abcinc.lcl\utility\aaa\File2.csv
          2 file(s) moved.
  
  RunAll script ran fine.
          1 file(s) moved.
          1 file(s) moved.
  
  RunAll script ran fine.
          1 file(s) moved.
          1 file(s) moved.
  
  Folder is NON empty
  A duplicate file name exists, or the file
  cannot be found.
  </code></pre>