title: Permission Denied on move or delete for last file in a folder
body: <p>I have an MS Access VBA procedure inside a module that has a for each loop on files in a particular folder.  </p>
  
  <p>Inside the loop, I create a new file in a separate folder that is then filled with cleaned data from the file in the loop.  I import the new file's data into a SQL Server 2005 database.  Upon successful import, the script deletes the cleaned file and <strong>attempts</strong> to move (or copy/delete) the file in the loop to an archive subfolder in the same directory.</p>
  
  <blockquote>
    <p><strong>The file looping works fine on all files in the looped folder... except for the last file.  That's when the Permission Denied error pops up.</strong></p>
  </blockquote>
  
  <p>The error message, under the above-mentioned circumstance, always happens on one of the following (I've tried several, similar commands):</p>
  
  <pre><code>fso.MoveFile
  fso.DeleteFile (just after copy)
  f.Move
  f.Delete (just after copy)
  Name origin As destination
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>Dim fso As New Scripting.FileSystemObject
  Dim f As file
  Dim processingFiles As Files
  
  If fso.FolderExists(incomingPath) Then
      Set processingFiles = fso.GetFolder(incomingPath).Files
  End If
  
  For Each f In processingFiles
  
      /*this is where the create a new file and clean it part runs - works fine*/
  
      If fso.FileExists(archivePathFile) Then
          Kill archivePathFile
      End If
  
      If fso.FileExists(tempPath &amp; "\cleaned_processing_file.txt") Then
          Kill tempPath &amp; "\clean_processing_file.txt"
      End If
  
  
      f.Move archivePathFile   '&lt;------------- Permission Denied, last file in folder
      Debug.Print f.Name &amp; " is now in " &amp; incomingPath &amp; "\Archive"
  
      'f.Copy archivePathFile, True 
      'f.Delete True '&lt;----------------------- Permission Denied, last file
  
      'Name origPathFile As archivePathFile '&lt; Path/File access error, last file
  
  Next '&lt;--- For Each Loop
  </code></pre>