Tuesday, February 05, 2008

Vbscript to delete a folder hierarchy

If you need to delete a folder hierarchy on a scheduled basis, you can use this vbscript along with the windows scheduler. You might want to consider adding some things like error handling, and logging to clean it up a bit.

Const DeleteReadOnly = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("D:\path\to\folder\*"), DeleteReadOnly
objFSO.DeleteFile("D:\path\to\folder\*"), DeleteReadOnly

In the above snippet, this will delete all folders and their contents below "folder", as well as file objects in the root of "folder".

No comments: