On 15.02.2021 15:22, Ammammata wrote:
>>> @echo off
>>> for %%i in (01 02 03 04 05 06 07 08 09 10 11 12) do (
>>> for /f "skip=1" %%j in ('dir /b o-n
>>> RSP_backup_202?_%%i_??_??????_???????.bak') do echo del %%j) 2>nul
> well, once removed the 'safety' echo, it does some deletions leaving just
> one file per month even if in an apparent random mode, I think there is a
> missing slash in dir /b o-n, should be dir /b /o-n
>
> let me try again, I worked on a copy ;)
>
> so, with the change it leaves just the first of each month, it's anyway a
> valid solution, thank you
Yes, the / was missing, but /o-n should leave the last of the month
whereas /on the first of the month.
If there are backups for more than a year, just specify the year which you
want to clean up:
@echo off
for %%i in (01 02 03 04 05 06 07 08 09 10 11 12) do (
for /f "skip=1" %%j in ('dir /b /o-n RSP_backup_2021_%%i_??_??????_???????.bak')