By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,222 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,222 IT Pros & Developers. It's quick & easy.

Delete Backup files Older than 5 days?

P: n/a
I have a database that backs up critical tables to a database, named
Backup with the date, daily. I can't figure out how to delete these
databases programmatically, say when they are 5 days old or older. I
was able to figure out how to delete them if they are 5 days older
then current date but the weekends and holiday, etc. leave some
undeleted.

Any help will be greatly appreciated,

ShyGuy
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
How exactly are you naming your files?

If you use BackupYYYYMMDD then it would be straightforward to test against
a value that was less than :
Backup & format(Date,"yyyymmdd")

Regards

Peter Russell

Shyguy previously wrote:
I have a database that backs up critical tables to a database, named
Backup with the date, daily. I can't figure out how to delete these
databases programmatically, say when they are 5 days old or older. I
was able to figure out how to delete them if they are 5 days older
then current date but the weekends and holiday, etc. leave some
undeleted.

Any help will be greatly appreciated,

ShyGuy


Nov 12 '05 #2

P: n/a
Thanks for the reply.

The backup db files are named - Backup Database 10-7-2003.mdb.

I could change it to the format you described, but I still don't know
how I could delete multiple files.

ShyGuy

On Wed, 8 Oct 2003 09:33 +0100 (BST), pr******@russellscott.co.uk
(Peter Russell) wrote:
How exactly are you naming your files?

If you use BackupYYYYMMDD then it would be straightforward to test against
a value that was less than :
Backup & format(Date,"yyyymmdd")

Regards

Peter Russell

Shyguy previously wrote:
I have a database that backs up critical tables to a database, named
Backup with the date, daily. I can't figure out how to delete these
databases programmatically, say when they are 5 days old or older. I
was able to figure out how to delete them if they are 5 days older
then current date but the weekends and holiday, etc. leave some
undeleted.

Any help will be greatly appreciated,

ShyGuy


Nov 12 '05 #3

P: n/a
Shyguy previously wrote:
Thanks for the reply.

The backup db files are named - Backup Database 10-7-2003.mdb.

I could change it to the format you described, but I still don't know
how I could delete multiple files.


This routine will do what I think you want, if you adopt this filenaming
approach. (It ignores the file extension)

Note that you can test it by renaming the files instead of deleting them.
The code is there for both so you can comment out/ de-comment the lines as
you want.
Make sure you have backups of any real data.

Put it into a standard module.

to run it just do
DelFiles

Regards

Peter Russell
Sub delfiles()
' finds all files in nominated folder with names in format
'backupyyyymmdd'
Dim strFldr As String
Dim strFile As String
Dim FileToGet As String

strFldr = "I:\largemdb" ' modify folder to your own
strFile = Dir(strFldr & "\backup*.*") ' get list of files in folder

Do While Len(strFile) > 0
FileToGet = Left(strFile, Len(strFile) - 4)
If Len(FileToGet) = 14 Then ' only check files with name of correct
length
If FileToGet <= CStr("BACKUP" & Format(Date - 5, "yyyymmdd")) Then
'comment/remove comment from next two statements as required

'next line renames
Name strFldr & "\" & strFile As strFldr & "\" & "OLD" & strFile
'next line deletes
'Kill strFldr & "\" & strFile
Else
' do nothing
End If
Else

'ignore file
End If

strFile = Dir
Loop

End Sub

Nov 12 '05 #4

P: n/a
Thank you so much. I changed the format of the saved files to what
you suggested and your code works beautifully. I wont tell you how
long I have been stumbling through trying to get this to work.

Thanks again,

ShyGuy
Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.