Function FolderCleanup(sourcepath as String, numdays as Integer, debugmode as String) As Integer ' function checks file dates in folder, sourcepath, and if more than numdays old, deletes the files ' note: this function has dependency for DoFileKill function ' sourcepath - folder path: e.g. c:\temp\ ' numdays - number of days back to allow before files are deleted ' debugmode - turns off print statement breadcrumbs Dim filenm as String ' file currently being checked Dim filedtstr as String ' file for filenm's last modified date, or create date Dim cutoffNDT as NotesDateTime ' today, adjusted back numdays to make cutoff date Dim fileNDT as NotesDateTime ' file's last modified/create date from filedtstr On Error Goto FErrorHandler ' get cutoff date Set cutoffNDT = New NotesDateTime(Today) Call cutoffNDT.AdjustDay(numdays * -1) ' adjust back by number of days If (debugmode="1") Then Print "(FolderCleanup) Cutoff date: " & cutoffNDT.DateOnly & ".
" End If ' get first file and loop through files filenm = Dir$(sourcepath, 0) If (debugmode="1") Then Print "(FolderCleanup) Processing folder: " & sourcepath & ".
" End If Do While filenm <> "" If (debugmode="1") Then Print "(FolderCleanup) Checking file: " & sourcepath & filenm & ".
" End If filedtstr = FileDateTime(sourcepath & filenm) If (debugmode="1") Then Print "(FolderCleanup) File system date: " & filedtstr & ".
" End If Set fileNDT = New NotesDateTime(filedtstr) If (fileNDT Is Nothing) Then ' cannot process doc Print "(FolderCleanup) Unable to set file NDT object w/ system date, " & filedtstr & ". Skipped file.
" Else ' compare dates (read like: if the fileNDT is less than the cutoffNDT, then do ...) If (fileNDT.TimeDifferenceDouble(cutoffNDT) < 0 ) Then ' file is old, kill If (debugmode="1") Then Print "(FolderCleanup) File, " & filenm & " is older than cutoff. Calling delete ...
" End If If (DoFileKill(sourcepath & filenm) = 1) Then ' kill success If (debugmode="1") Then Print "(FolderCleanup) File, " & filenm & " deleted sucessfully.
" End If Else ' kill failed, print note and continue Print "(FolderCleanup) File, " & filenm & " could not be deleted!
" End If End If ' loop filenm = Dir$() Loop ' done looping, return success If (debugmode="1") Then Print "(FolderCleanup) Completed looping.
" End If FolderCleanup = 1 FExit: Exit Function FErrorHandler: Print "(FolderCleanup) Unexpected Error: " & Cstr(Err) & ", " & Error$ & ", on line: " & Cstr(Erl) FolderCleanup = 0 Resume FExit End Function