Hi,
I have the code below that deletes all files in a folder with a specific file name. How can I adapt it so it deletes all files that contain a specific text string?
So in the example, my files all end in 'Summary File v1.pptx' (eg. 'London Summary File v1.pptx', Manchester Summary File v1.pptx' etc..) so I want to find them all and delete them - any ideas?
Thanks.
I have the code below that deletes all files in a folder with a specific file name. How can I adapt it so it deletes all files that contain a specific text string?
So in the example, my files all end in 'Summary File v1.pptx' (eg. 'London Summary File v1.pptx', Manchester Summary File v1.pptx' etc..) so I want to find them all and delete them - any ideas?
Thanks.
Code:
Private fso As Object
Public Sub DeleteFiles()
Set fso = CreateObject("Scripting.FileSystemObject")
RecurseDelete "C:\Users\Steve\Desktop\2018 Data\", "Summary File v1.pptx"
End Sub
Private Sub RecurseDelete(currentFolder As String, fileToDelete As String)
Dim thisFolder As Object
Dim subFolder As Object
If fso.FileExists(currentFolder & fileToDelete) Then fso.DeleteFile currentFolder & fileToDelete, True
Set thisFolder = fso.GetFolder(currentFolder)
For Each subFolder In thisFolder.subFolders
RecurseDelete subFolder.Path & "\", fileToDelete
Next subFolder
End Sub
Last edited: