How to empty recycle bin in batch

I need code to empty the recycle bin without conformation. I tried a simple del $Recycle.Bin , but it says that access is denied, even when it is promoted, does anyone know the code that I could use.

+6
source share
4 answers

This freed my mailbox without any confirmation.

 @ECHO OFF start /b /wait powershell.exe -command "$Shell = New-Object -ComObject Shell.Application;$RecycleBin = $Shell.Namespace(0xA);$RecycleBin.Items() | foreach{Remove-Item $_.Path -Recurse -Confirm:$false}" 
+2
source

I just found this.

 erase /s/q/f "C:\$RECYCLE.BIN\*">nul 
+1
source

It is guaranteed that all contents in the Recycle Bin are deleted for the selected drive, leaving the folder intact:

 C:\$Recycle Bin\>rd . /q /s 
  • Switch to the desired drive
  • Go to the $Recycle Bin folder
  • Run the rd . /q /s command rd . /q /s rd . /q /s [remove-dir (currentdir) / quiet / subdir]

A message appears stating that the current directory is still in use (since this is your current location) and cannot be deleted. This is the expected behavior, because I want the $Recycle Bin folder to remain.

+1
source

The above answers are suitable for cmd batch files, but there is a better way for the new powershell

Just use the cmdlet

Clear-RecycleBin

Optionally, you can use the -Force or -Confirm: $ false options so that it does not ask for confirmation

For more information open powershell and type

Get-Help Clear-RecycleBin

0
source

All Articles