Smazání adresáře včetně vnořených položek

Funkce:

Public Function KillFolder(ByVal FullPath As String) As Boolean

   
'Parametry: FullPath = plná cesta k adresáři, který má být smazán
   'Vrací logickou hodnotu výsledku mazání
   'Je třeba přidat referenci na Microsoft Scripting Runtime
   'Příklad volání: KillFolder ("C:\bordel")

   On Error Resume Next
   Dim oFso As New Scripting.FileSystemObject

   
'metoda deletefolder nemá ráda "\" na konci cesty

   If Right(FullPath, 1) = "\" Then FullPath = _
   Left(FullPath, Len(FullPath) - 1)

   If oFso.FolderExists(FullPath) Then

      'Nastavením druhého parametru na True maže i read-only soubory
      oFso.DeleteFolder FullPath, True
      KillFolder = Err.Number = 0 And oFso.FolderExists(FullPath) = False
   
   
End If

End Function

Zpět

Autor: The Bozena