keepcalculator

06 Numbers and Powers

Schedule Auto Empty Recycle Bin in Windows

Card No. 06·54871 · Updated · Standard formula, shown below

This guide shows you how to set up automatic emptying of the Recycle Bin on Windows using the built-in Task Scheduler and a simple command-line tool. You’ll create a scheduled task that permanently deletes files older than a set number of days, keeping your bin from filling up without any manual effort.

What You’ll Need

  • A Windows PC (Windows 10 or Windows 11 recommended)
  • Administrator account access (to create the scheduled task)
  • Basic familiarity with File Explorer and the Start menu

Step-by-Step

  1. Open Task Scheduler. Press Win + R, type taskschd.msc, and press Enter. Alternatively, search for “Task Scheduler” in the Start menu and open it.
  2. Create a new task. In the right-hand panel, click Create Basic Task… to launch the wizard.
  3. Name the task. Enter a descriptive name like “Empty Recycle Bin Weekly” and optionally add a description. Click Next.
  4. Choose the trigger. Select how often you want the task to run (e.g., Weekly). Click Next.
  5. Set the schedule. Pick the day and time (e.g., every Sunday at 3:00 AM). Click Next.
  6. Select the action. Choose Start a program and click Next.
  7. Enter the program and arguments. In the Program/script field, type cmd.exe. In the Add arguments (optional) field, paste the following (replace 7 with the number of days you want to keep files):
    /c "forfiles -p "C:\$Recycle.Bin" -s -m *.* -d -7 -c "cmd /c del /f /q @path""
    This command tells Windows to delete files in the Recycle Bin that are older than 7 days.
  8. Finish the wizard. Click Next, review the summary, and click Finish.
  9. Adjust advanced settings (optional). Right-click your task in the Task Scheduler Library, select Properties, and under the General tab, check Run with highest privileges to ensure the task can access all files. Under Conditions, uncheck Start the task only if the computer is on AC power if you want it to run on battery as well.
  10. Test the task. Right-click the task and select Run to make sure it executes without errors. Check the Last Run Result column in Task Scheduler to confirm success (0x0 means success).

Common Mistakes

  • Wrong path to the Recycle Bin: The Recycle Bin is stored at C:\$Recycle.Bin for the system drive. If your bin is on another drive (e.g., D:), you need to add that path too, or the task won’t clean that drive’s bin.
  • Missing quotes around the path: The path contains a space? No, it doesn’t, but if you modify it to include a folder with spaces, you must wrap it in double quotes. In the command above, the path is already quoted.
  • Using the wrong command: Some guides suggest using rd /s /q (remove directory) which can delete the entire Recycle Bin folder structure. Stick with del to delete files only.
  • Not running with admin rights: If the task isn’t set to run with highest privileges, it may fail to delete certain protected files.
  • Typo in the argument: The command is long and easy to mistype. Copy-paste it directly from this guide to avoid errors.

Tips

  • Test with a short retention period first: Set the days to 1 and run the task manually to verify it works before setting a longer period.
  • Use a separate task for each drive: If you have multiple drives with Recycle Bins, create one task per drive, each with its own path.
  • Combine with a notification: In Task Scheduler, you can add an email action (requires SMTP setup) to get notified when the task runs, but this is often overkill.
  • Check the task history: In Task Scheduler, click on your task and view the History tab to see detailed logs of each run.
  • Consider using a third-party tool: If you prefer a GUI, tools like “BleachBit” can schedule auto-cleaning, but the built-in method is free and reliable.

Troubleshooting

Task runs but files remain: This usually means the command can’t find the Recycle Bin path. Verify the path exists by opening File Explorer and typing C:\$Recycle.Bin in the address bar. If you see a “You don’t have permission” error, you need to run the task as administrator.

Task fails with error 0x2: This means the program (cmd.exe) couldn’t be found. Ensure you typed cmd.exe correctly in the Program/script field.

Task runs but only deletes some files: The forfiles command may not handle hidden or system files properly. Add the /a flag to include them: forfiles /a -p ... but be careful—this could delete files you want to keep.

Task doesn’t run at all: Check if the task is enabled. In Task Scheduler, right-click the task and select Enable. Also, check the Conditions tab—if “Start the task only if the computer is on AC power” is checked and you’re on battery, it won’t run.

Command syntax error: If you see a message like “ERROR: The system cannot find the file specified,” double-check the command for typos. The quotes around the path are essential.

Frequently Asked Questions

Will this permanently delete files, bypassing the Recycle Bin?

Yes, the command deletes files directly from the Recycle Bin, so they cannot be restored. Make sure you really want to permanently remove them.

Can I set it to empty the bin every day?

Yes, in the trigger settings, choose Daily and set the time. The command will run daily and delete files older than the specified number of days.

Does this work on Windows 7 or 8?

Yes, Task Scheduler and forfiles are available on Windows 7 and later. The path to the Recycle Bin is the same.

What if I want to keep files for 30 days instead of 7?

Simply change the -d -7 part to -d -30. The number after the minus sign is the age in days.

Is there a way to do this without Task Scheduler?

You could use a startup script or a third-party utility, but Task Scheduler is the most reliable built-in method.

Will this affect files I’ve pinned to the Recycle Bin?

No, the Recycle Bin doesn’t support pinning. All files in the bin are subject to deletion based on age.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →