I've pretty much copy and pasted the following script together which is intended to recurse through a directory deleting old .gz files based on CreationDate.
However I get an error stating that the object doesn't support that property, but I know that is a valid prop. What am I missing?
'Get the date, subtract 180 days, convert to YYYYMMDD format dtmDate = Date - 180 strDay = Day(dtmDate) If Len(strDay) < 2 Then strDay = "0" & strDay End If strMonth = Month(dtmDate) If Len(strMonth) < 2 Then strMonth = "0" & strMonth End If strYear = Year(dtmDate) strTargetDate = strYear & strMonth & strDay
CleanUp "E:\MonitorArchive\Archive"
Sub CleanUp(strFolderPath) Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FolderExists(strFolderPath) Then DeleteContent objFSO, strFolderPath End If End Sub
Sub DeleteContent(objFSO, strFolderPath) Dim objFolder : Set objFolder = objFSO.GetFolder(strFolderPath) Dim objFile Dim strDate For Each objFile In objFolder.Files
strDate = Left(objFile.CreationDate, 8) ' <--- Error Line
If strDate < strTargetDate Then If objFile.Extension = "gz" Then objFile.Delete True End If End If Next
Dim objSubFolder For Each objSubFolder In objFolder.SubFolders DeleteContent objFSO, objSubFolder.Path objSubFolder.Delete True Next End Sub