Solved Batch file to delete all backup files except 3 most recent

September 26, 2016 at 10:25:14
Specs: win 10
I have a back up routine with one piece of software that that's creates folders on every program exit which are then zipped and stored in a different folder.

Since these folders can be created several times a day, I get a lot of them, and in my main back-up routine, I do not need all of them.

I'd like a batch file to delete all folders except the most recent 3, and the same for all files,except the most recent 3 files.

message edited by ColMac


See More: Batch file to delete all backup files except 3 most recent

Reply ↓  Report •


#1
September 27, 2016 at 02:59:39
✔ Best Answer
:: test on COPIES before releasing the safety
::
::
::
::====== script starts here ===============
::
:: keep3new.bat 2016-09-27 16:53:48.40
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

pushd d:\files
dir/b/ad/o-d > myfile

:main
for /f "tokens=* skip=3 delims= " %%a in (myfile) do (
echo rd /s /q "%%a"
)
goto :eof
::====== script ends here =================

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#2
September 28, 2016 at 05:20:56
Thanks. Just copying it to try. Will report back later (probably not today as going out now)

Thanks again


Reply ↓  Report •

Related Solutions


Ask Question