Recursively Deleting Folders
erich November 30th, 2006
Sometimes, you run into cases where you need to delete a folder recursively throughout a directory. Case in point - CVS, or Code Versioning System, creates a CVS folder within each folder in your parent directory. In a web environment, you might end up with:
- \css
- \CVS
- \images
- \CVS
- \gui
- \CVS
And so on. Manually removing these folders is about as much fun as a skin graft, so I wrote a quick and dirty VBScript to handle it for me.
-
Option Explicit
-
On Error Resume Next
-
ShowFolderList("C:\path\to\your\folder")
-
-
Function ShowFolderList(folderspec)
-
'{
-
Dim fso, f, f1, s, sf
-
Set fso = CreateObject("Scripting.FileSystemObject")
-
Set f = fso.GetFolder(folderspec)
-
Set sf = f.SubFolders
-
-
For Each f1 in sf
-
'{
-
ShowFolderList(f1.path)
-
-
if strcomp(f1.name,"CVS") = 0 then
-
'{
-
fso.deletefolder f1.path, true
-
'Exit for
-
'Exit function
-
'}
-
End if
-
'}
-
Next
-
'}
-
End Function
You could always modify this script to take several command line arguments representing paths to directories you'd like to clean out, improving the versatility of this script.
tags: beyrent, cvs, delete, erich, folder, recursive, script, vbscript, windows
- Technology
- Comments(0)

