title: Why can't I delete this folder (VBA)?
body: <p>I created a temporary folder that gets deleted later on in the program using this code: </p>
  
  <pre><code>    'Creates a new temporary      directory path for a folder copy
      If dir("C:\\InventorTempFolder\\\", vbDirectory) = "" Then       
  MkDir "C:\\InventorTempFolder\\\"
  SetAttr "C:\InventorTempFolder", vbNormal
      Else: MsgBox "This folder already exists."
      End If
  </code></pre>
  
  <p><br></p>
  
  <p>(I don't know if the SetAttr is right...that's part of my question!)</p>
  
  <p>I then pulled this code offline that should delete all the files and directories in this folder, using this code:</p>
  
  <pre><code>Sub DeleteDirectory()
  
  
  Dim dir_name As String
  Dim file_name As String
  Dim files As Collection
  Dim i As Integer
  dir_name = "C:\\InventorTempFolder"
  
  ' Get a list of files it contains.
  Set files = New Collection
  file_name = dir$(dir_name &amp; "\*.*", vbReadOnly + _
      vbHidden + vbSystem + vbDirectory)
  Do While Len(file_name) &gt; 0
      If (file_name &lt;&gt; "..") And (file_name &lt;&gt; ".") Then
          files.Add dir_name &amp; "\" &amp; file_name
      End If
      file_name = dir$()
  Loop
  
  ' Delete the files.
  For i = 1 To files.Count
      file_name = files(i)
      ' See if it is a directory.
  If GetAttr(file_name) = vbDirectory Then
          Kill file_name
  Else: Kill file_name
  End If
  
  Next i
  
  ' The directory is now empty. Delete it.
  RmDir dir_name
  
  ' Remove the read-only flag if set.
  ' (Thanks to Ralf Wolter.)
  
  End Sub
  </code></pre>
  
  <p><br></p>
  
  <p>However, the directory won't delete. My theory is that it is because the directory is a read-only folder. That is why I tried to change the attribute to vbNormal, but it won't change. So questions I'm wondering is:
  <br></p>
  
  <ol>
  <li><p>Why won't it delete? Is my theory right that it is because it is read-only?</p></li>
  <li><p>If so, how can I fix that?</p></li>
  <li><p>If not, what else is wrong...?</p></li>
  </ol>
  
  <p><br></p>
  
  <p>Thanks ahead of time!</p>