' Удаление старых данных АвтоГРАФ
' Путь к данным АвтоГРАФ
Dim agData
agData = "D:\АвтоГРАФ\Data"
' Сколько данных оставить (число лет)
Dim agSafe
agSafe = 3
Dim fsoHandle, fsoData, fsoFolders, fsoFolder, fsoFiles, fsoFile
Dim curDate, curDay, curMonth, curYear, minDate
Set fsoHandle = CreateObject("Scripting.FileSystemObject")
If fsoHandle.FolderExists(agData) Then
curDate = Date()
curDay = Day(curDate)
curMonth = Month(curDate)
curYear = (Year(curDate) Mod 100)-agSafe
If curDay<10 Then
curDay = "0" & curDay
End If
If curMonth<10 Then
curMonth = "0" & curMonth
End If
If curYear<10 Then
curYear = "0" & curYear
End If
minDate = curYear & curMonth & curDay
Set fsoData = fsoHandle.GetFolder(agData)
Set fsoFolders = fsoData.SubFolders
For Each fsoFolder In fsoFolders
Set fsoFiles = fsoFolder.Files
For Each fsoFile In fsoFiles
If Mid(fsoFile.Name,1,8)=fsoFolder.Name & "-" And _
Mid(fsoFile.Name,9,6)<minDate And _
Mid(fsoFile.Name,15,5)=".sbin" Then
fsoFile.Delete
End If
Next
Next
End If |