ClearHistory10_20

Delete folders named in format [PDFs-2020-12-05] in certain folder along with their content.
Providing number of days to keep and number of days to delete.

Example: to keep folders of last 22 days and delete 40 days before that use
Call ClearHistory10_20("/OrdersPDFs/", 22, 40)


Public

Tested

My Own Work
Sub ClearHistory10_20(ParentFolder, Days_GoBack, Days_2Delete)
    ' Clear history files
    '    Go 10 days back and delete 10 days back
    '
    ' Days_GoBack                = 6
    ' Days_2Delete            = 30
    ' Response.Write "Days_2Delete = " & Days_2Delete
    ' Response.Write "
"
    ' Response.Write "Days_GoBack = " & Days_GoBack
    ' Response.Write "
"
    ' Response.Write "From: " & Date - (Days_2Delete + Days_GoBack)
    ' Response.Write "
"
    ' Response.Write "To: " & Date - Days_GoBack
    ' Response.Write "
"
    For I = Date - (Days_2Delete + Days_GoBack) To Date - Days_GoBack
        ThaFolder            = ParentFolder & "PDFs-" & FileDate_Formatted("", I, 1)
        ' Response.Write "
" & ThaFolder
        If FS.FolderExists(Server.MapPath(ThaFolder)) Then
            ' Response.Write " <<-- Found, will be deleted"
            Set folder         = fs.GetFolder(Server.MapPath(ThaFolder))
            For Each item in folder.Files
                item.delete
                ' Response.Write " . "
            Next
            folder.delete
        End If
    Next
End Sub

ParentFolder, Days_GoBack, Days_2Delete

Go back 15 days and clear 60 days before that
Call ClearHistory10_20("/OrdersPDFs/", 15, 60)

Go back 7 days and clear 20 days before that
Call ClearHistory10_20("/OrdersPDFs/", 7, 20)

Views 250 Downloads 86

Classic ASP Date+Time
ANmarAmdeen
791
Attachments
Revisions

v1.0