0

I have created a batch file that deletes all .txt files in a folder and its sub directories. But now I need it to delete all files before a certain date because I want it to keep the .txt files created in the last 60 days. I need to delete 1.6 million files and the code below is most efficient for that.

Here is my code:

cd /BASE_PATH
del /s *.txt

How can I edit the code above to delete files before 8/19/15?

I need to keep similar code because other methods of deleting .txt files are too slow for my file amounts.

TevinTwoTimes
  • 103
  • 1
  • 10
  • 1
    You can use the FORFILES command to accomplish that. http://ss64.com/nt/forfiles.html – Squashman Oct 21 '15 at 21:04
  • 1
    Possible duplicate of [batch file to delete files older than a specified date](http://stackoverflow.com/questions/324267/batch-file-to-delete-files-older-than-a-specified-date) – TessellatingHeckler Oct 21 '15 at 21:15

1 Answers1

2

Here you go,

forfiles -p "C:\folder1\folder2" -s -m *.* -d <Number of days> -c "cmd /c del @path"

For Windows7 you may use

forfiles -p "C:\folder1\folder2" -s -m *.* /D -<Number of days> /C "cmd /c del @path"
Shyam Bhimani
  • 1,310
  • 1
  • 22
  • 37
Mr Konstantinos
  • 193
  • 1
  • 1
  • 11