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 make a scheduled process in Windows (specifically, Windows 7) that every 3 hours will delete all the files in all folders older than 24 hours (like the Unix find's -mtime +1). Basically the Windows equivalent of having this configured in my Unix cron:

find $TRANSITDIR -mtime +1 -exec rm -rf {} \;

Although I seem to have found that the Windows cron equivalent is the scheduler, I just don't know the Windows commands to do that.

Does anyone have a scheduler script ready-to-go?

share|improve this question

migrated from Jul 29 '11 at 15:43

This question came from our site for system and network administrators.

Related: The solution I posted (using PowerShell) can be fairly easily modified to work on any folder or drive, not just the recycle bin, and can be scheduled using the Task Scheduler GUI or the command-line schtasks.exe. – Indrek Nov 5 '12 at 21:28

Create a batch file with the following contents:

REM Remove files older than 1 day
forfiles /p %1 /s /m * /c "cmd /c del @path /q" /d -1

Then open Windows Task Scheduler. Create a basic task to run a program, and as the argument give the path to the folder in quotes.

Explanation of commands

REM is a comment.

forfiles will run a command for each file. /p %1 defines what path the files are in (%1 means the value of the first command line argument passed to the script). /s is recursive (goes into subfolders). /m *.* is the file name mask. /c "cmd /c del @path" specified what command to execute. /d -1 means files older than 1 day.

In this case, cmd /c del @pat /qh creates a new session and runs del (delete file) on @path, the file path for each file iterated over by forfiles. /q is for quiet mode, so that it doesn't ask you to confirm for directories.


Replace del with echo. This will print each file that would have been deleted, instead of actually deleting it.

share|improve this answer

Not exactly what you want to do, but I'd say that the automatic clearings of ccleaner are worth to take in consideration when talking about windows. I use it to find and clean tmp files for windows machines.

It has a limited CLI

Also provided that you're a shell guy and you said you need it for W7, you can try powershell:

share|improve this answer

You must log in to answer this question.

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