If I have a folder within a folder (subfolder). The subfolders name contains the word "Copy". How would I code in Excel to delete all subfolders containing this word?
I have managed this far, but it deletes all the subfolders.
Private Sub CommandButton1_Click()
Dim FSO As Object
Dim oPath As String
Set FSO = CreateObject("scripting.filesystemobject")
oPath = Blad1.Cells(2, 4).Value
If Right(oPath, 1) = "\" Then
oPath = Left(oPath, Len(oPath) - 1)
End If
If FSO.FolderExists(oPath) = False Then
MsgBox oPath & " doesn't exist"
Exit Sub
End If
On Error Resume Next
'Delete files
'FSO.deletefile oPath & "\*.*", True
'Delete subfolders
FSO.deletefolder oPath & "\*.*", True
On Error GoTo
End Sub