batch file question in deleting files
Posted on 2013-06-04
I currently have a batch file that almost does what I need it to do. This script deletes everything in the specified folder or I can specify a file type to keep.
What I need to do is, I would like for a script to be able to specify to ONLY delete a certain type of file, and keep every other file in the same directory. I also would like the script to keep for example 5 copies of extension .pdf, but delete the oldest ones and only keep the 5 newest according to the date. Basically, to be able to specify which extension I need deleted and how many of the newest files to keep.
So this is what I have so far, but I'm not sure how to modify it, or create a new script to do what I need it to do. I need something that will work in a batch file.
@echo off (delete all files in this directory)
for /R "%BaseDir%" %%D in (.) do (
echo Processing directory "%%~fD"
for /F "skip=%FilesToKeep% tokens=*" %%F in ('dir /A-D /O-D /B "%%~fD\%FileFilter%" 2^>NUL') do (