Solved Kill a Folder

sergio vieira

Member
Local time
Today, 12:56
Joined
Apr 22, 2024
Messages
35
Good morning. Greetings to everyone from Portugal. I have a folder in c:\Patrigest\Properties. Inside this Folder, I have a Folder with subfolders. I need to, from time to time, delete this folder and subfolders. I tried several ways and... nothing. The folder
Captura de ecrã 2025-03-23 104507.png
does not delete. How can I do this? I appreciate your help.
 
Can you delete it manually?

From ChatGPT.
Code:
Sub DeleteFolderAndSubfolders()
    Dim fso As Object
    Dim folderPath As String

    ' Set the folder path you want to delete
    folderPath = "C:\YourFolderPath" ' Change this to the actual folder path

    ' Create a FileSystemObject
    Set fso = CreateObject("Scripting.FileSystemObject")

    ' Check if the folder exists before attempting to delete it
    If fso.FolderExists(folderPath) Then
        fso.DeleteFolder folderPath, True ' True forces deletion without confirmation
        MsgBox "Folder and its subfolders deleted successfully.", vbInformation, "Success"
    Else
        MsgBox "Folder does not exist.", vbExclamation, "Error"
    End If

    ' Clean up
    Set fso = Nothing
End Sub
 
Dear friend. Thanks a lot. Solved. Greetings
 

Users who are viewing this thread

Back
Top Bottom