Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 519
09stephenb Avatar asked Jan 14 '14 09:01

09stephenb


2 Answers

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}"
like image 162
Knuckle-Dragger Avatar answered Sep 24 '22 14:09

Knuckle-Dragger


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

like image 36
DGaleano Avatar answered Sep 25 '22 14:09

DGaleano