dim FSO
dim fil
dim strFolder
dim objFolder
Dim totalbytes
strFolder = "c:\deleteme"
Set fso = createobject("scripting.filesystemobject")
Set objFolder = FSO.GetFolder(strfolder)
totalSize_recur objFolder, totalbytes
msgbox "TotalBytes " & totalbytes & vbcrlf & "Target is: " & 2^30
If totalbytes > 2^30 Then
dateCheck_recur objFolder
End If
Sub totalSize_recur(fldr, overallsize)
Dim subFolder
overallsize = overallsize + fldr.size
For Each subFolder In fldr.subfolders
totalSize_recur subFolder, totalbytes
next
End Sub
Sub dateCheck_recur(fldr)
Dim subFolder
For each fil in fldr.files
If fil.datecreated < Now - 7 Then
fil.delete
End If
Next
For Each subFolder In fldr.subfolders
dateCheck_recur subFolder
Next
If fldr.files.count = 0 and fldr.subfolders.count = 0 Then fldr.delete
End Sub
|