Empty contents of a directory – vbs


Esempio:

strFolder = "\\netapp\Home_Share\TransitOLD"
intDays = 
 
Set objFSO	  = CreateObject("Scripting.FileSystemObject")
Set objFolders  = objFSO.GetFolder(strFolder)
objToday				= Now()
objPastDate	 = DateAdd("d", intDays*-1, objToday)
 
Recurse objFolders



Sub recurse(ByRef objFolders)
 
	Set objSubFolders = objFolders.SubFolders
	Set objFiles = objFolders.Files
 
	for each File in objFiles
		if File.DateLastModified < objPastDate then
			On Error Resume Next
			File.Delete
		end if
	Next
 
	For Each Folder in objSubFolders
		If Folder.DateLastModified < objPastDate Then
			objFSO.DeleteFolder Folder.Path, True
		Else
			Recurse Folder
		End If
	Next
 
	Set objSubFolders = Nothing
	Set objFiles = Nothing
 
end Sub