Solved script for deleting files from folder except the newest file

May 26, 2019 at 03:56:15
Specs: Windows 7
for my work I am trying to write a script that can delete all files for a folder except the newest file, all the files in the folder are the same.
i already now how to write a script that delete all the files but i do not find a way to not delete the newest file

thanks


See More: script for deleting files from folder except the newest file

Report •

#1
May 26, 2019 at 10:30:47
Don't have a bat file for you, but here are two links that might be of interest:

https://www.horstmuc.de/wbat32.htm#...

https://chi.home.xs4all.nl/utilitie...

MIKE

http://www.skeptic.com/


Report •

#2
May 26, 2019 at 12:10:42
✔ Best Answer
Neither of those seem to do what FORFILES doesn't do, outside of additional datetime resolution with the second.

Also, when trying to keep only the latest file(s), it's better to not make assumptions about datetimes.

Note: This has been presented as generic as possible since the OP lacks details. As written, it will delete itself if there's a newer file in the same directory.

for /f "skip=1 delims=" %%a in ('dir /a-d /o-d /b') do del "%%a"

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •
Related Solutions


Ask Question