Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
The
dir /a:d /o:-d /t:w /b %DIRNAME% command
will return a list of subdirectories in the given directory, sorted in descending order by modification date, skip the first N entries from this list (N is the number of days for which you want to backup) , delete the rest.
Schematically, the code will look like this:
set "DIRNAME=c:\TEMP"
set "N=10"
for /f "usebackq skipto=%N% tokens=* delims=" %%a in ('dir /a:d /o:-d /t:w /b %DIRNAME%') do (
echo.RD /S /Q "%DIRNAME%\%%~a"
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question