title: Batch file appending text to the end of a .txt file is locking the file
body: <p>We have a process that uses a batch file which, in short, repeatedly gets some plain text data and appends it to the end of a .txt file for later processing. When the data is processed, the .txt is deleted.</p>
  
  <p>This is done in a very simple and basic way by using the ">>" operator to append the data to the .txt file, then a 'DEL' cmd to delete the .txt file.</p>
  
  <p>However, one user is having an issue running this. They are able to append data to the .txt file but are unable to delete it as the file seems to be locked. They get this message when the batch file tries to delete:</p>
  
  <p>"The process cannot access the file because it is being used by another process."</p>
  
  <p>The .txt file being created is on a network drive, and no other user is able to delete the file (or change it, etc.) either.</p>
  
  <p>However, if the user with the problem reboots their PC, the file is able to be edited and deleted (which seems to suggest that there is some process on the user's PC that is using the file).</p>
  
  <p>The below batch file is an extremely simplified demo I made which experiences the issue for the user, but not for anyone else. This is not the 'real' process of course, but illustrates the issue without any superfluous code and is totally independent of anything else that the main process is doing.</p>
  
  <pre><code>:: we want to repeatedly append text to the end of a txt file
  echo test &gt;&gt; test.txt
  echo test &gt;&gt; test.txt
  echo test &gt;&gt; test.txt
  
  pause
  
  :: but then we cannot delete the file as it appears to be locked
  del test.txt
  
  pause
  </code></pre>
  
  <p>The user with the issue has just got a new PC using Windows 10. Everyone else is using Windows 7. Maybe that is the root of the issue, but I don't know why? I understand that command prompt had some changes for Win10, but they sound pretty cosmetic.</p>
  
  <p>Any pointers would be appreciated. I've been scouring the Internet for hours and can't find anything like this issue. Maybe I am doing something so fundamentally wrong that no one would have encountered this?!</p>
  
  <p>Thanks in advance.</p>