Thursday, December 11, 2008

SCRIPT: Delete Directories and Files inside a Directory

on error resume next
Dim oFS

Dim sDir
sFolder= "C:\TEMP"

Set oFS = CreateObject("Scripting.FileSystemObject")
sDir = oFS.GetAbsolutePathName(sFolder)
DeleteFolder oFS.GetFolder(sDir)

Sub DeleteFolder(oFld)
Dim oItem
Dim strFileName
On Error Resume Next

For Each oItem In oFld.Files
strFileName = oItem.Path
oItem.Delete True
Next
For Each oItem In oFld.SubFolders
DeleteFolder oItem
Next
If 0 = oFld.Files.Count And 0 = oFld.SubFolders.Count Then
oFld.Delete True
End If
End Sub

No comments: