how to empty recyclebin through command prompt?

2019-01-12 20:22发布

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?

11条回答
Fickle 薄情
2楼-- · 2019-01-12 20:28

To stealthily remove everything, try :

rd /s /q %systemdrive%\$Recycle.bin
查看更多
走好不送
3楼-- · 2019-01-12 20:30

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 insider PowerShell without confirmation, you can use Clear-RecycleBin -Force. Official documentation can be found here

查看更多
姐就是有狂的资本
4楼-- · 2019-01-12 20:33
SAY GOODBYE
5楼-- · 2019-01-12 20:39

i use these commands in a batch file to empty recycle bin:

del /q /s %systemdrive%\$Recycle.bin\*
for /d %%x in (%systemdrive%\$Recycle.bin\*) do @rd /s /q "%%x"
查看更多
Explosion°爆炸
6楼-- · 2019-01-12 20:39

All of the answers are way too complicated. OP requested a way to do this from CMD.

Here you go (from cmd file):

powershell.exe /c "$(New-Object -ComObject Shell.Application).NameSpace(0xA).Items() | %%{Remove-Item $_.Path -Recurse -Confirm:$false"

And yes, it will update in explorer.

查看更多
SAY GOODBYE
7楼-- · 2019-01-12 20:42

while

rd /s /q %systemdrive%\$RECYCLE.BIN

will delete the $RECYCLE.BIN folder from the system drive, which is usually c:, one should consider deleting it from any other available partitions since there's an hidden $RECYCLE.BIN folder in any partition in local and external drives (but not in removable drives, like USB flash drive, which don't have a $RECYCLE.BIN folder). For example, I installed a program in d:, in order to delete the files it moved to the Recycle Bin I should run:

rd /s /q d:\$RECYCLE.BIN

More information available at Super User at Empty recycling bin from command line

查看更多
登录 后发表回答