How to empty the Windows Recycle Bin automatically
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
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.
- Right-click on the desktop or another folder and select New > Text Document.
- Paste the following line of code into the document: PowerShell.exe -NoProfile -Command Clear-RecycleBin -Confirm:$false
- Save the document.
- Rename it to emptyrecyclebin.bat. Make sure the file has the .bat extension and not .bat.txt.
- Test the file once to make sure it works.
The next step depends on the Windows edition. If you run professional or Enterprise editions, do the following:
- Open the Start Menu.
- Type gpedit.msc and select the result to load the Group Policy Editor.
- Go to Computer Configuration > Windows Settings > Scripts > Shutdown
- Double-click on Shutdown to open its Properties.
- Select Add.
- Use the Browse option to pick the emptyrecyclebin.bat that you created previously.
- 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:
- Open Explorer.
- Type in the address bar shell:startup. This should open the startup folder.
- 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
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.
- Use the shortcut Windows-I to open the Settings application.
- Go to System > Storage.
- Select "Change how we free up space automatically" on the Storage page.
- Toggle Storage sense to "On".
- Set a desired period for the feature, e.g. every day, week, month, or on low disk space.
- Check "Delete temporary files that my apps aren't using".
- 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).
- 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.
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.
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?
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!
rd /s “D:\$Recycle.bin”
rd /s “C:\$Recycle.bin”
Roll over effect in that the icon will show trash; click–all is gone.
Thank you
Good. But to do this with cmd, whats is the right command to put in the .bat file?
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/
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.
Nice tip, Martin. Thank you.
However, I prefer to use CCleaner Professional. :)
@Mark Hazard
I use CCleaner Free v5.31.6105
And use secure file deletion. Complex overwrite (7 passes)
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.
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.
Yes, this is what I’ve been doing since forever. I strongly dislike the recycle bin.
To empty the temp directory I use this one liner:
del /kqsxyz %temp\*
;-)
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.
@Ivan: Do people shutdown their PCs?
I shut down my work PC every evening. It’s required by my employer for security reasons.
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 ?
Very nice tip, thanks!
Very useful, thanks so much!
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
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.
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.