How to delete files more than X days old

November 1, 2010 at 12:27:17
Specs: Windows XP
Hi all,

I am trying to write a batch that will look thru a directory of folders called "history" and delete contents in it that are more 7 days old, that is rooted in the C:\test directory.
For Example:

so far I have this:
@echo on

set folder=%C:\test\

for /r %folder% %%A in (.) do If %%~nA equ history (find * -type f -mtime +7)


This does a good job of going to the "history" folders, but I am having a hard time with the delete parameter, as I cant find anything that will look at modified time of the files. Researching on the internet i found many references to this "find" statement that has a parameter -mtime that is supposed to look at modified time, but in the above it is pretty useless. Obviously I am doing something wrong. If you anyone could guide me to the proper command, I would appreciate very much.


See More: How to delete files more than X days old

November 1, 2010 at 23:40:21
Your question has been asked thousands of times. Search the forum using the search dialog box at the top of this page.

Did you Google for an answer before asking the question?

Report •

April 21, 2011 at 20:13:02
I think I have written a VBScript application that does what you want and a bit more :) The code is zipped up and can be downloaded via the linked to page!

* The code that I have allows you to Delete and/or archive files by specifying ...
1.)directory to be searched
2.) age of the file
3.) Use regular expressions to allow for pattern matching file names.

The script is highly configurable and creates a log of actions taken on files matching your criteria.

Report •
Related Solutions

Ask Question