title: The system cannot find the file specified (randomly occurs)
body: <p>I have a batch file in which I download files from an FTP server. Before hand it creates a folder based on the date/time. If there are no files to download the program delete the file. However it only deletes the files 90% (give or take) of the time. The other times it throws the error <code>The system cannot find the file specified</code>. I am not sure what makes the difference or why occasionally it doesn't work. If makes a difference the batch script is being run on a Windows Server 2012 R2.</p>
  
  <pre><code>ping ##.#.###.# -n 1 -w 1000
  set FileName=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%_%TIME:~0,2%-%TIME:~3,2%
  
  if %errorlevel% EQU 1 (
      :: Create timestamp of failed ping
      echo "Unable to ping. Timestamp: %FileName%" &gt; "Archive-FileTransferProd\%FileName%.txt"
  ) else (
  
      :: Create folder on server based on current datetime (24 hour)
      md %FileName%
  
      :: FTP Commands
      :: Logg in to FTP
      echo user %UserName%&gt; ftpCmd.dat
      echo %Password%&gt;&gt; ftpCmd.dat
      echo prompt&gt;&gt; ftpCmd.dat
  
      :: Copy items to server
      echo lcd "%FileName%"&gt;&gt; ftpCmd.dat
      echo mget *&gt;&gt; ftpCmd.dat
  
      :: Delete files on server
      ::echo mdel *&gt;&gt; ftpCmd.dat
  
      :: Disconnect and clean up connection
      echo disconnect&gt;&gt; ftpCmd.dat
      echo bye&gt;&gt; ftpCmd.dat
      ftp -n -s:ftpcmd.dat %Server%
      del ftpCmd.dat
  
  
      set cnt=0
      for %%A in ("%FileName%\*") do set /a cnt+=1
  
      echo File name = %FileName%
      echo Count is = %cnt%
  
      :: If the folder is empty delete it
      IF %cnt% EQU 0 (
      echo File Deleted?
          rd /S /Q "C:\FileTransfer\%FileName%"
      ) 
  
  )
  </code></pre>
  
  <p><strong>Additional Info</strong></p>
  
  <p>I have been going through the command prompt and found the following. The code used doesn't assign the proper name to the folder. This happens whether the code is <code>md %FileName%</code> or <code>md "%FileName%"</code></p>
  
  <p><a href="https://i.stack.imgur.com/GQohV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GQohV.png" alt="enter image description here"></a></p>