Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

4 Answers 4

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
            objFile.Delete
        End If
    Else
        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.

example:

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: http://www.petri.co.il/download_free_reskit_tools.htm 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.