| Delete a Folder and all Sub-Folders, including Hidden and Read-Only Files Public Function KillFolder(ByVal FullPath As String) _ As Boolean '****************************************** 'PURPOSE: DELETES A FOLDER, INCLUDING ALL SUB- ' DIRECTORIES, FILES, REGARDLESS OF THEIR ' ATTRIBUTES 'PARAMETER: FullPath = FullPath of Folder to Delete 'RETURNS: True is successful, false otherwise 'REQUIRES: 'VB6 'Reference to Microsoft Scripting Runtime 'Caution in use for obvious reasons 'EXAMPLE: 'KillFolder("D:\MyOldFiles") '****************************************** On Error Resume Next Dim oFso As New Scripting.FileSystemObject 'deletefolder method does not like the "\" 'at end of fullpath If Right(FullPath, 1) = "\" Then FullPath = _ Left(FullPath, Len(FullPath) - 1) If oFso.FolderExists(FullPath) Then 'Setting the 2nd parameter to true 'forces deletion of read-only files oFso.DeleteFolder FullPath, True KillFolder = Err.Number = 0 And _ oFso.FolderExists(FullPath) = False End If End Function |
Delete a Folder and all Sub-Folders, including Hid |
Express News India | Freelance ecommerce web development India