how to empty recyclebin through command prompt?
Solution 1
You can effectively "empty" the Recycle Bin from the command line by permanently deleting the Recycle Bin directory on the drive that contains the system files. (In most cases, this will be the C:
drive, but you shouldn't hardcode that value because it won't always be true. Instead, use the %systemdrive%
environment variable.)
The reason that this tactic works is because each drive has a hidden, protected folder with the name $Recycle.bin
, which is where the Recycle Bin actually stores the deleted files and folders. When this directory is deleted, Windows automatically creates a new directory.
So, to remove the directory, use the rd
command (remove directory) with the /s
parameter, which indicates that all of the files and directories within the specified directory should be removed as well:
rd /s %systemdrive%\$Recycle.bin
Do note that this action will permanently delete all files and folders currently in the Recycle Bin from all user accounts. Additionally, you will (obviously) have to run the command from an elevated command prompt in order to have sufficient privileges to perform this action.
Solution 2
I prefer recycle.exe
from Frank P. Westlake. It provides a nice before and after status. (I've been using Frank's various utilities for well over ten years..)
C:\> recycle.exe /E /F
Recycle Bin: ALL
Recycle Bin C: 44 items, 42,613,970 bytes.
Recycle Bin D: 0 items, 0 bytes.
Total: 44 items, 42,613,970 bytes.
Emptying Recycle Bin: ALL
Recycle Bin C: 0 items, 0 bytes.
Recycle Bin D: 0 items, 0 bytes.
Total: 0 items, 0 bytes.
It also has many more uses and options (output listed is from /?).
Recycle all files and folders in C:\TEMP:
RECYCLE C:\TEMP\*
List all DOC files which were recycled from any directory on the C: drive:
RECYCLE /L C:\*.DOC
Restore all DOC files which were recycled from any directory on the C: drive:
RECYCLE /U C:\*.DOC
Restore C:\temp\junk.txt to C:\docs\resume.txt:
RECYCLE /U "C:\temp\junk.txt" "C:\docs\resume.txt"
Rename in place C:\etc\config.cfg to C:\archive\config.2007.cfg:
RECYCLE /R "C:\etc\config.cfg" "C:\archive\config.2007.cfg"
Solution 3
nircmd lets you do that by typing
nircmd.exe emptybin
http://www.nirsoft.net/utils/nircmd-x64.zip
http://www.nirsoft.net/utils/nircmd.html
Solution 4
You can use a powershell script (this works for users with folder redirection as well to not have their recycle bins take up server storage space)
$Shell = New-Object -ComObject Shell.Application
$RecBin = $Shell.Namespace(0xA)
$RecBin.Items() | %{Remove-Item $_.Path -Recurse -Confirm:$false}
The above script is taken from here.
If you have windows 10 and powershell 5 there is the Clear-RecycleBin
commandlet.
To use Clear-RecycleBin
inside PowerShell without confirmation, you can use Clear-RecycleBin -Force
. Official documentation can be found here
Solution 5
To stealthily remove everything, try :
rd /s /q %systemdrive%\$Recycle.bin
Related videos on Youtube
user1016403
Updated on July 26, 2022Comments
-
user1016403 almost 2 years
Usually we delete the recycle bin contents by right-clicking it with the mouse and selecting "Empty Recycle Bin". But I have a requirement where I need to delete the recycle bin contents using the command prompt. Is this possible? If so, how can I achieve it?
-
Matthew Lock over 9 yearsI just let Windows automatically delete the oldest files when the Recycle Bin reaches its maximum size superuser.com/questions/69284/…
-
user324747 about 4 yearsIs there a way that doesn't require the extra step of using admin cmd prompt? It's OK if it only does my account, I only use one account on my PC.
-
-
Synetech almost 11 yearsA few more caveats: • the change in bin status may not reflect in Explorer (the desktop icon) until you actually open the Recycle Bin and/or refresh the desktop, • it only affects that particular volume; recycled files on other drives will not be affected, so you may not be actually emptying the recycle bin with this method, and • the directory name can vary by Windows version (and I believe filesystem as well). It may be
$Recycle.bin
,Recycled
,Recycler
, etc. and you may even have more than one if you multi-boot—programs like Norton Recovery Bin have their own directories. -
Pacerier about 9 yearsDoesn't this have the same problem Synetech mentioned? stackoverflow.com/questions/9238953/…
-
kodybrown about 9 years@Pacerier I don't show the Recycle Bin on my desktop, so I never noticed before whether the icon updates or not. After just testing it, the icon is updated correctly after emptying via recycle.exe. As far as the directories are concerned, I expect that it is using a Win32 API to empty the Recycle Bin. Having said that, I have used this util for many years on Windows including XP, 7, 8, 8.1 and Server 2003, 2012, 2012 R2. (I probably used it on Vista and Server 2008, but didn't run those OSes very long, so I can't say for certain..)
-
Pacerier almost 9 years@Synetech, How do we figure out is it
$Recycle.bin
,Recycled
, orRecycler
? Is there a variable to do that, or is the only way via catching the exceptions? -
Pacerier almost 9 yearsYea, it's not a particularly useful tool, especially since there are in-built ways to do it already.
-
kodybrown almost 9 years@Pacerier built in ways!? Like navigating Windows Explorer with the keyboard and/or mouse? Using the icon on the desktop (assuming the recycle bin is even displayed on the desktop)? Neither of which solve the op's question. I really do think there is a command somewhere for emptying the bin, like deleting history
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
but I haven't found it. So, please, if you have a built-in way, please share it! -
Phill almost 9 yearsAhhhh I've been trying to figure out why the suggested commands above didn't work. Specifying f: for mine made it work. Thanks a lot! <3
-
Pacerier almost 9 years? Isn't the solution at stackoverflow.com/a/27327957/632951 considered built-in?
-
zb226 over 8 years@Pacerier: First you suggest this solution has flaws like the
RD /S [/Q]
solution - which @wasatchwizard refuted by testing - then the exact sameRD /S [/Q]
solution suddenly is superior, because it's "built-in". How does that make sense?RD /S [/Q]
has the problems @Synetech described. This solution does not. -
Jin almost 8 yearsClear RecycleBin is useful in PowerShell in windows 10
-
James Ko over 7 yearsNote: If you're using this in a script, you will also want to pass in a
/q
switch sord
doesn't give you an extra prompt.rd /s /q %SYSTEMDRIVE%\$Recycle.bin
-
npocmaka over 7 yearsVery nice improvement of batch/powershell chimera technique (+1). Is the
iex
-ing your idea? (btw it is possible to embed C# code in batch file with msbuild inline tasks without need of compiling exe) -
rojo over 7 years@npocmaka Thanks! I think many others have used
iex
this way. I forget where I picked up that${%~f0}
is equivalent togc "%~f0"
. It was this cat who turned me ontoout-string
. Can you link an example of embedding C# in a batch script with msbuild? My Google-fu is weak today. -
npocmaka over 7 yearshere - dostips.com/forum/… - though you cannot pass command line arguments directly - you'll need to define a variable with the arguments that later can be extracted from the c# part
-
npocmaka over 7 yearsand in the example above .net version is not parametrized.
-
shareef over 6 yearsthanks i needed that when i had alot in my recycle and windows clicks to empty dose not work thanks.
-
Rahul over 6 years@shareef Thank you for the comment :)
-
jdhao over 5 yearsDoes not work on my Windows 10. Nothing happens after using this command.
-
Arcsector about 5 yearsReminder this only works in CMD. If you want it to run in powershell, try
cmd /c "rd /s %systemdrive%\$Recycle.bin"
-
S. Tarık Çetin over 3 years
Clear-RecycleBin
successfully deleted some malformed folder names in recycle bin that I could not remove otherwise. -
Zimba about 3 yearsWin 10 doesn't have $Recycle.Bin in drive root
-
Zimba about 3 yearsIn Win 10, Recycle Bin is an app; doesn't respond to right clicks in start menu
-
Zimba about 3 yearsWin 10 doesn't have a %systemdrive%\$Recycle.bin directory
-
alexsupra about 3 yearsJust checked Windows 10 Pro build 2004 and it does. Maybe you should enable option of showing hidden/system files and folders in your file manager.
-
Zimba about 3 yearsWorks, the gives error:
Clear-RecycleBin : The system cannot find the path specified At line:1 char:1 + Clear-RecycleBin -Force + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (RecycleBin:String) [Clear-RecycleBin], Win32Exception + FullyQualifiedErrorId : FailedToClearRecycleBin,Microsoft.PowerShell.Commands.ClearRecycleBinCommand
-
Zimba about 3 yearsAha! Found it: Command still works, but file wasn't visible in explorer; I'd already selected
Show Hidden files
, and wasn't visible in C: drive. It does become visible when I uncheckHide protected operating system files
(separate option). Cheers. -
Zimba about 3 yearsrundll32.exe advpack.dll,DelNodeRunDLL32 doesn't empty bin for me: Win 10.0.17134. Fixed: works in Elevated prompt.
-
Tom McDonald about 3 yearsIf you want to see the contents before deleting type cd / then cd $Recycle.bin then dir */s
-
oliiix over 2 years@Zimba of course it doesn't. everyone here is just making things up that sound cool