I have two parameters. It was suggested that this is a duplicate question, but I want to specify a minimum age AND a minimum number of files to be kept. I'm not sure how to combine those parameters.
I have a batch file which includes this code:
@echo off
set "backupDir=[BACKUP DIR PATH HERE]"
copy /Y "[PATH OF FILE TO BE COPIED]" "[PATH WHERE BACKUP IS SAVED]"
for /f "skip=4 delims=" %%a in ('dir "%backupDir%\" /b /a-d /o:-d') do del "%backupDir%\%%a"
It creates a backup of a database and deletes everything except the four most recent instances. What I want is to make sure that if the batch file is run more than once in a day, I don't end up deleting the old files and end up with four copies of what would essentially be the same backup.
How can I specify that the file must be at least "N" days old before deletion?
It might be better to have something that limits the file from running again if it hasn't been at least 24 hours since the last time. But I don't know how to do that either.