Purging old files from a windows directory

In Windows, is there an easy way to say “delete all the files in a particular directory which are older than 14 days old”, or something of that sort?

It seems like it ought to be trivially easy, but I can’t figure out a quick way to do it without writing a nastily intricate batch file. And of course, anything that involves recursively and automatically deleting files is NOT something you want to get wrong.

Thanks…

Alas, with the functions built into Windows, no.

I had to have the automation team here at work write me an application to do just that.

There are some tools that will allow you to search by date (3rd party), and for some basic things I use SizeExplorer Pro (but work paid for licenses).

I agree that it’s annoying though.

Good luck with the god awful script/batch file.

You can always do this manually in Windows Explorer by clicking on the Date Modified column to sort in date order, then you can highlight everything older than a given date and delete those files.

Don’t forget that ‘last modified’ doesn’t necessarily mean ‘last used’ - there is a ‘last accessed’ timestamp, but I’m not sure that will help either if, for example, the disk indexing service, or your antivirus software causes it to be updated every time it does a scan.

And that’s exactly one of my biggest issues here at work. Too many processes “access” the file, and change the stamp.

I really wish there was a better way to manage this. (I deal with about 80Tb of data on 40 servers or so. And users won’t delete anything regularly!)

One way I have found to sort-of deal with such uncertainty is to first make an archive copy of the files suspected to be redundant, then just rename or move them; if they were required, it will quickly become evident; if not, they can be deleted after a reasonable buffer time.

On our servers we use a little exe called LogClean.exe that we got free from somewhere. It includes the exe and then instructions on how to write a .bat, and also logs its doings in a log file. We run the bat from Scheduled Tasks (it doesn’t have to be scheduled, though)

We use it to delete IIS log files and SQL baks over 15 days old. Works great for us.

But I can’t seem to find it anywhere, not even SourceForge. Email or PM me if you want it for yourself.