I have a directory into which I backup MySQL dbs in a folder with the current date.
Now after 30 or 60 days I like to only keep the n latest folders in that backup d
These two different lines work. Keeping all files there might be in the backupDir while deleting only the selected N latest nameDir folders.
This is adjusted from @JosefZ's comment Windows Batch Script to only keep the N latest FOLDERS in a directory
for /f "skip=2 delims=" %%a in ('dir "%backupDir%\" /B /O:-N /A:D') do echo rd rd /s /q "%backupDir%\%%a"
This also works taken from @Magoo's answer from here https://stackoverflow.com/a/17521693/1010918
for /f "skip=2 delims=" %%a in (' dir "%backupDir%\" /b /ad-h /o-d') do rd /s /q "%backupDir%\%%a"
Find the complete working Batch Script here Windows Batch Script to backup local MySQL databases & only keep N latest FOLDERS with backup files if you like.
Thank you all for your help!