I have a backup directory with the the date in the filenames to mark when a database was backup-ed. I want to search the directory and return the filename with the latest backup date. (Not last modified date)
Format looks like this (always)
FileName_mmddyyyy.accdb
Thus in C:\BackupDbDir might have the following Accounts database files
Accounts_02022014.accdb
Accounts_02032014.accdb
Accounts_02022015.accdb
I want to return the variable = Accounts_02022015.accdb
I figured out how to loop through directory and extract date information but am stuck from there. I do not know how to turn these into dates and compare.
Ideas?
Format looks like this (always)
FileName_mmddyyyy.accdb
Thus in C:\BackupDbDir might have the following Accounts database files
Accounts_02022014.accdb
Accounts_02032014.accdb
Accounts_02022015.accdb
I want to return the variable = Accounts_02022015.accdb
I figured out how to loop through directory and extract date information but am stuck from there. I do not know how to turn these into dates and compare.
Ideas?
Code:
Dim f, tmp
f = Dir("C:\BackupDbDir\Accounts_*.accdb")
Do While Len(f) > 0
tmp = Mid(f, 6, 8)
Debug.Print tmp
f = Dir()
Loop