Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to set up an automatic task that will automatically delete files older than X days from a specific folder. I'd prefer to do it without having to install any 3rd party software, but I'll be ok if it's a very small and simple utility.

I want this to force me to keep my files organized. I am setting my browser to download to a standard folder, and then with this script to automatically delete files older than a week, I will be forced to move & organize downloaded files I want to keep.

share|improve this question
up vote 2 down vote accepted

How about Belvedere from one of Lifehacker's editors.

alt text

share|improve this answer

This is pretty easy with Windows Scripting Host. A sample script looks something like this:

numDays = 7

Set objfso = CreateObject("Scripting.FileSystemObject")
Set objFile = objFso.GetFile("C:\test.txt")

Sub DeleteOldFile(objFile, numDays)
    dateFile = objFile.DateLastModified
    dateToday = Now()

    If dateFile <= dateToday Then
        daysOld = dateToday - dateFile
        If daysOld > numDays Then
        End If
        WScript.Echo "Incorrect date stamp in", strFile
    End If

End Sub

You would need to write your script then run it as a scheduled task. Maybe thirty minutes after you log on on Friday mornings to give yourself one last chance to get those files you want to keep moved. The complete source for this example.

share|improve this answer

I coded myself a solution for this a while back right before I found DelOld. It's a very small tool which does exactly what you want, and it is available as a .jar file, wrapped java executable, Visual Basic executable (MSVBVM60.DLL required), and of course as source code.

Simply supply it 2 command-line arguments -- the path of the folder, and the number of days before a file should be deleted. It can also be run through a batch script via Task Scheduler.


DelOld.exe "C:\Downloads" 30

This will delete all files older than 30 days under C:\Downloads.

share|improve this answer

There's a windows command called forfiles. I think it was on the windows 2000 resource kit. I found a link to it from petri's web site: It has a lot you can do with it including removing individual files based on how old they are or whole directories.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .