Here is a script that will delete the oldest files in a folder until the folder is below the MaxFolderSize
Const ZFPFolderPath = "\\C\Temp\"
Const MaxFolderSize = 15
Const ConvertToGigs = 1073741824
Const adVarChar = 200
Const MaxCharacters = 255
Const adFldIsNullable = 32
Const adDouble = 5
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "FileName", adVarChar, MaxCharacters
DataList.Fields.Append "FileDate", adVarChar, MaxCharacters
DataList.Open
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(ZFPFolderPath)
if objFolder.Size/ConvertToGigs > MaxFolderSize Then
Set colFiles = objFolder.Files
For Each objFile in colFiles
DataList.AddNew
DataList("FileName") = objFile.Path
i = hour(objFile.DateCreated)
if i < 10 then
DataList("FileDate") = year(objFile.DateCreated) & "/" & month(objFile.DateCreated) & "/" & day(objFile.DateCreated) & " 0" & i & ":" & minute(objFile.DateCreated) & ":" & second(objFile.DateCreated)
else
DataList("FileDate") = year(objFile.DateCreated) & "/" & month(objFile.DateCreated) & "/" & day(objFile.DateCreated) & " " & i & ":" & minute(objFile.DateCreated) & ":" & second(objFile.DateCreated)
End If
DataList.Update
Next
DataList.Sort = "FileDate ASC"
DataList.MoveFirst
Do Until objFolder.Size/ConvertToGigs < MaxFolderSize
objFSO.DeleteFile(DataList.Fields.Item("FileName"))
DataList.MoveNext
Loop
End If
Patrick McNamara, BS-IS/CS, MBA, MAED
ASP.NET Web Application Developer
Asteryx, LLC.
http://asteryx.com
pat@asteryx.com