Monday, July 6, 2009

VBS Script - Recursively Delete all Files in a Folder

This script deletes all files under a particular folder, in this example c:\test.

set objFSO = createobject("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder("C:\test")

for each folder in objFolder.SubFolders
objFSO.DeleteFolder folder.path, True
next

for each file in objFolder.Files
objFSO.DeleteFile file.path, True
next

2 comments:

  1. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.

    ReplyDelete