pesquisando na web achei esse codigo pra excluir backup antigo
so que nao consigo escluir meus backup antigos, tipo quero excluir os backup com 40 dias
Db_Agro.fdb_20-03-2021.zip
Db_Agro.fdb_17-03-2021.zip
Db_Agro.fdb_18-03-2020.zip
Db_Agro.fdb_02-03-2020.zip
- Código:
On Error Resume Next
Dim DataInicial As Date, DataFinal As Date
Dim CONTADOR As Long
CONTADOR = 0
Dim ArquivoDel As String
DataInicial = Data1
DataFinal = Data2
Do While DataInicial <= DataFinal
ArquivoDel = SeparaArquivo(CurrentDb.Name, False) & "Db_Agro.fdb_" & IIf(Day(DataInicial) > 9, Day(DataInicial), "-" & Day(DataInicial)) & IIf(Month(DataInicial) > 9, Month(DataInicial), "-" & Month(DataInicial)) & Year(DataInicial) & ".zip"
Kill (ArquivoDel)
If Err.Number > 0 Then
MsgBox Err.Description
Err.Clear
Else
CONTADOR = CONTADOR + 1
End If
DataInicial = DataInicial + 1
Loop
MsgBox "Foram excluídos " & CONTADOR & " arquivos de backup!", vbInformation
so que nao consigo escluir meus backup antigos, tipo quero excluir os backup com 40 dias
Db_Agro.fdb_20-03-2021.zip
Db_Agro.fdb_17-03-2021.zip
Db_Agro.fdb_18-03-2020.zip
Db_Agro.fdb_02-03-2020.zip