How to delete archived files?

rodneyb

Registered User.
Local time
Today, 21:36
Joined
Jul 3, 2003
Messages
84
Hi,

I have some vba code which copies the current database to an archive directory and zips it up and renames it with a date/time stamp.

This archiving code is initiated on a daily basis therefore as you can imagine the number of archive files will soon add up. I want to be able to add code so that any old archive files, say 20 days old, is deleted, and therefore keeping the number of files archived to a minimum.

Is there any access code which will check the date/time of when the file was created so that I can check and see how old it is in order to determine whether to delete the file or not?

Cheers.
 
Aha - got it going using this code:

Dim checkFile
checkFile = Dir(archivePath & "\*.zip", vbDirectory) ' Retrieve the first entry.
Do While checkFile <> "" ' Start the loop.
If (Now - FileDateTime(archivePath & "\" & checkFile)) > 20 Then
Kill archivePath & "\" & checkFile 'Delete file as it is older than 20 days
End If
checkFile = Dir ' Get next entry.
Loop

:D
 

Users who are viewing this thread

Back
Top Bottom