09stephenb
09stephenb

Reputation: 9836

How to empty recycling bin in batch

I need a code to empty the recycling bin without conformation I have tried the simple del $Recycle.Bin but it says access denied even when elevated does any one know a code I could use.

Upvotes: 7

Views: 14147

Answers (5)

user22115593
user22115593

Reputation: 1

I thought the /s parameter had to come before the /q:
rd /s /q C:\$Recycle.Bin should be the command to run and empty recycle bin from a batch file, right?

Upvotes: 0

DGaleano
DGaleano

Reputation: 127

Above answers are ok for cmd batch files but for the new powershell there is a better way

Simply use the cmdlet

Clear-RecycleBin

Optionally you can use the -Force or -Confirm:$false parameters so it won't ask for confirmation

For more info open powershell and type

Get-Help Clear-RecycleBin

Upvotes: 2

Altered-Ego
Altered-Ego

Reputation: 476

Guaranteed to delete all content in the Recycle Bin for the selected drive while leaving the folder itself intact:

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

You will get an error that the current directory is still in use (because that is your current location) and can't be deleted. This is expected behaviour because I want the $Recycle Bin folder to remain.

Upvotes: 1

Knuckle-Dragger
Knuckle-Dragger

Reputation: 7066

This emptied my bin 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}"

Upvotes: 2

09stephenb
09stephenb

Reputation: 9836

I have just found this.

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

Upvotes: 1

Related Questions