Delete File

492JQS

Access Muppet
Local time
Today, 23:42
Joined
Aug 27, 2004
Messages
9
This is a shortened version of a problem I posted in the General Forum a week or so ago but have had no response to. Maybe I'll have more luck here.
I'm using the following code to delete backup files older than ten days:

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

I'm using the code on the onload event of my switchboard, and the problem is that if the database is not used for 10 days or more it deletes all my backup files! Is there a way to modify the code so it doesn't delete the newest file, even if it is older than 10 days?
 
Maybe you could "Move" the file to another directory.
Then, if Dir="", you move the file again, back to where it was.
Else, you delete it and move another one.
 
I had to do something similar to this but I created a temp table to hold the file names in and then sorted the table by last edited date/time. And then Delete all the files starting with the 2nd record.
 

Users who are viewing this thread

Back
Top Bottom