How to empty the Windows Recycle Bin automatically

Martin Brinkmann
Apr 12, 2019
Windows
|
22

All files that you delete regularly on Windows are moved to the Recycle Bin first. Designed as a last resort to recover accidentally deleted files, files that sit in the Recycle Bin may sit there for a long period. While that is not a huge problem most of the time, if disk space is scarce, it may be frustrating to empty the Recycle Bin manually regularly.

You could set a custom Recycle Bin size to avoid it occupying too much space on a drive, or, use automation to clear the Windows Recycle Bin regularly.

This guide offers a general solution to the Recycle Bin problem, and a specific solution that is only available on Windows 10 devices.

General Solution for all Windows versions

powershell delete recycle bin files

The following method is compatible with all Windows versions and editions. It requires the creation of a batch file and running that batch file either using a policy or as a startup command.

  1. Right-click on the desktop or another folder and select New > Text Document.
  2. Paste the following line of code into the document: PowerShell.exe -NoProfile -Command Clear-RecycleBin -Confirm:$false
  3. Save the document.
  4. Rename it to emptyrecyclebin.bat. Make sure the file has the .bat extension and not .bat.txt.
  5. Test the file once to make sure it works.

empty recycle bin shutdown

The next step depends on the Windows edition. If you run professional or Enterprise editions, do the following:

  1. Open the Start Menu.
  2. Type gpedit.msc and select the result to load the Group Policy Editor.
  3. Go to Computer Configuration > Windows Settings > Scripts > Shutdown
  4. Double-click on Shutdown to open its Properties.
  5. Select Add.
  6. Use the Browse option to pick the emptyrecyclebin.bat that you created previously.
  7. Select ok.

Windows will execute the script (to delete Recycle Bin content) when Windows shuts down automatically from that moment on.

You can use the same process to delete the script again if you don't want to use it anymore.

If you run Windows 10 Home, you may execute the script on startup by placing it in the startup folder:

  1. Open Explorer.
  2. Type in the address bar shell:startup. This should open the startup folder.
  3. Drag and drop the script to the folder.

Windows will execute the script on startup automatically from that moment on. You can delete the script again if you don't want to use it anymore. (via Major Geeks)

Storage Sense on Windows 10

empty recycle bin windows 10 automatically

Microsoft's Windows 10 operating system comes with a new feature called Storage Sense; you may configure it to delete Recycle Bin content, and other temporary files, regularly and automatically.

  1. Use the shortcut Windows-I to open the Settings application.
  2. Go to System > Storage.
  3. Select "Change how we free up space automatically" on the Storage page.
  4. Toggle Storage sense to "On".
  5. Set a desired period for the feature, e.g. every day, week, month, or on low disk space.
  6. Check "Delete temporary files that my apps aren't using".
  7. Set the desired period that deleted files need to sit in the Recycle Bin untouched before Windows deletes the files. The default period is 30 days, you may change that to 1, 14 or 60 days (or never).
  8. If you don't want files in the download folder to be deleted automatically, make sure that setting is set to "never".

Windows will from that moment on delete files in the Recycle Bin if the time they have been in the recycle bin untouched exceeds the selected period.

Summary
How to empty the Windows Recycle Bin automatically
Article Name
How to empty the Windows Recycle Bin automatically
Description
Find out how to delete files that are in the Recycle Bin on Windows machines automatically on shutdown or on start of the system.
Author
Publisher
Ghacks Technology News
Logo
Advertisement

Tutorials & Tips


Previous Post: «
Next Post: «

Comments

  1. Julius said on April 16, 2019 at 5:19 am
    Reply

    If anyone found that putting the script here:

    Group Policy >> Computer Configuration > Windows Settings > Scripts > Shutdown

    does not work for them it has to do with permissions and elevated privileges (which I found out the hard way after much fiddling and head scratching).

    To make the script work properly add like this:

    Group Policy >> User Configuration > Windows Settings > Scripts > Logoff

    Hope this helps anyone who was struggling to get this to work.

  2. Julius said on April 15, 2019 at 8:16 am
    Reply

    The bat file works if I click on it manually but if added via Group Policy to run at shutdown it does not execute.

    I have 2 user accounts, could it be I need to specify which one needs the Recycle Bin cleared?

  3. ULBoom said on April 14, 2019 at 3:25 pm
    Reply

    gpedit isn’t in Windows Home versions.

    I have a few bat file shortcuts on the desktop to flush dns, delete email cache, chromium cache, etc. and click them when needed. Only issue I’ve had is something, AV, Win Security Center, not sure what, deleted them; resetting File Security fixed that.

    How hard is it drag recycle bin to desktop, then right click/delete recycle bin contents? You do have to look at the icon, then move a finger but really?

    Sarcasm aside, this is a good intro to startup and shutdown files and how to write them. Find all the junk chrome won’t delete on shutdown and clear that too!

  4. VioletMoon said on April 13, 2019 at 8:40 pm
    Reply

    rd /s “D:\$Recycle.bin”
    rd /s “C:\$Recycle.bin”

    Roll over effect in that the icon will show trash; click–all is gone.

    1. Stefan said on April 14, 2019 at 8:36 am
      Reply

      Thank you

  5. Stefan said on April 13, 2019 at 9:26 am
    Reply

    Good. But to do this with cmd, whats is the right command to put in the .bat file?

  6. haha said on April 13, 2019 at 6:41 am
    Reply

    Clear-RecycleBin does not work on win8.1 (powershell 4.0).

    It is a powershell 5.0 cmdlet: https://www.jaapbrasser.com/clear-recyclebin-new-powershell-5-0-cmdlet-available-in-windows-10/

    1. Mark Hazard said on April 13, 2019 at 3:21 pm
      Reply

      It is easy enough to obtain Powershell 5 or 6 for Windows 8.1. I have done it, and have tested Martin’s solution with Powershell Core 6.2. It works well.

  7. Mark Hazard said on April 12, 2019 at 9:44 pm
    Reply

    Nice tip, Martin. Thank you.
    However, I prefer to use CCleaner Professional. :)

    1. Rush said on April 13, 2019 at 3:19 am
      Reply

      @Mark Hazard

      I use CCleaner Free v5.31.6105

      And use secure file deletion. Complex overwrite (7 passes)

  8. VioletMoon said on April 12, 2019 at 6:23 pm
    Reply

    Right click–Properties–Don’t Move Files to the Recycle Bin; remove files immediately.

    Still a feature from XP days that is on Windows 10 Pro, all versions. Never has changed.

    1. wangychungy said on April 12, 2019 at 10:28 pm
      Reply

      Yup, same here, ha.. I stopped using the recycle bin many years ago. I’m just aware, and don’t delete stuff by mistake, at least yet. Thus I save time by not having to fuss with the recycle bin. Also, I know how to recover deleted files if need be, which is a hassle, but overall the better choice for me.

    2. John Fenderson said on April 12, 2019 at 7:33 pm
      Reply

      Yes, this is what I’ve been doing since forever. I strongly dislike the recycle bin.

  9. Emil said on April 12, 2019 at 11:37 am
    Reply

    To empty the temp directory I use this one liner:

    del /kqsxyz %temp\*

    ;-)

  10. Ivan said on April 12, 2019 at 11:29 am
    Reply

    Do people shutdown their PCs?
    I do so only if updates force me, otherwise I let it sleep.
    I’ve seen people who even just let it run and don’t even sleep it.

    I deliberately use the recycle bin, by not hitting shift+delete, as that bypasses it.
    Then the size of the recycle bin is set to a sensible size and it doesn’t bother me if stuff in there sits for a month.

    1. John Fenderson said on April 12, 2019 at 7:31 pm
      Reply

      @Ivan: Do people shutdown their PCs?

      I shut down my work PC every evening. It’s required by my employer for security reasons.

    2. ilev said on April 12, 2019 at 6:53 pm
      Reply

      I never shut down my PC. My PC is running tasks 24/7.
      I don’t understand the need for an auto emptying recycle bin. Just right click the icon and select ’empty recycle bin’. How hard can it be ?

  11. michal_3city said on April 12, 2019 at 11:11 am
    Reply

    Very nice tip, thanks!

  12. Julius said on April 12, 2019 at 10:33 am
    Reply

    Very useful, thanks so much!

  13. Bart from Holland said on April 12, 2019 at 9:40 am
    Reply

    This a nice article Martin, been looking for something like this for years.
    I would like to clear the TEMP folder when computer shuts down.
    Viruses like police virus, go to the TEMP folder and when computer starts
    the next time, become active. When the TEMP folder be empty before the next start
    that can not become a problem anymore.

    No i use a shortcut to a batchfile, to shut down the computer.
    See below.
    Thanks.

    @echo off
    rd %temp% /s /q
    md %temp%
    cls
    cd\
    cd Windows
    rd Temp /s /q
    md Temp
    cls
    shutdown /s /f /t 10

    1. Shiva said on April 12, 2019 at 6:25 pm
      Reply

      I could be wrong, but didn’t you write a post about RAMDisk and Firefox portable? All the rest follows from this.
      About the Recycle Bin… Maybe is possible use a junction link instead the script.

    2. Dave said on April 12, 2019 at 5:51 pm
      Reply

      I just created a 2GB ramdrive (B:) and set my user varible to use a temp folder there.

      Then I created a task to run at the logon that creates the folders I need on B:.

      I’ve also edited my FF config to locate the cache in that location as well.

      If you manually control all updates and don’t mind changing the system varibles back and forth when needed you can also set the system varible to use this location and temporarily set it to a non volatile location for any updates that require temporary files to exist on boot.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.