I had a need recently to traverse the subdirectories below a certain directory on my system and delete any directory whose name matched a specific string.
For example, imagine that you wanted to delete any subdirectory in your D:\Test directory whose name included the word "log". The following code would do that:
deleteMatchingSubdirs "D:\Test", "log"
The subroutine performing the actual deletion work appears below. Note that this script will delete – without confirmation – any matching subdirectory. So be careful. If you fed it the string "e" it would delete every subdirectory that contained an "e" in the name. If you fed it "Temp" it would delete directories with names like "Temp", "Temporary", "ExTemporaneous", "JustaTempDir".
' ' Delete matching subdirectories ' sub deleteMatchingSubdirs(theDirectory, matchString) set theFso = CreateObject("Scripting.FileSystemObject") set theFolder = thefso.getfolder(theDirectory) for each thisDir in theFolder.subfolders folderName = thisdir.name if instr(1,foldername,matchString) > 0 then thefso.deletefolder theDirectory & "\" & foldername end if next end sub