Nov 30

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.

VBScript:
  1. Option Explicit
  2. On Error Resume Next
  3. ShowFolderList("C:\path\to\your\folder")
  4.  
  5. Function ShowFolderList(folderspec)
  6. '{
  7. Dim fso, f, f1, s, sf
  8. Set fso = CreateObject("Scripting.FileSystemObject")
  9. Set f = fso.GetFolder(folderspec)
  10. Set sf = f.SubFolders
  11.  
  12. For Each f1 in sf
  13. '{
  14. ShowFolderList(f1.path)
  15.  
  16. if strcomp(f1.name,"CVS") = 0 then
  17. '{
  18. fso.deletefolder f1.path, true
  19. 'Exit for
  20. 'Exit function
  21. '}
  22. End if
  23. '}
  24. Next
  25. '}
  26. 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: , , , , , , , ,