How To Delete Directories With Long File Names RRS feed

  • Question

  • FYI,

    I ran across a problem with deleting directories with long file names.  I had accidentally set a backup incorrectly and it recursively saved data.  Windows is limited to 260 characters.  I tried all sorts of things to delete the data.  I finally discovered that Windows Scripting Runtime will handle it with some special characters in front of the directory name.  It recursively deletes the directory. 

    Sub deldir()
      Dim fso As New Scripting.FileSystemObject
      Dim dn As String
      dn = "C:\directory_you_want_to_delete"
      If fso.FolderExists(x) Then
        fso.DeleteFolder ("\\?\" & dn) 'needs \\?\ prefix
      End If
    End Sub

    Saturday, May 30, 2015 1:37 AM