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?
相关问题
- How to Debug/Register a Permanent WMI Event Which
- the application was unable to start correctly 0xc0
- Inheritance impossible in Windows Runtime Componen
- how to get running process information in java?
- Is TWebBrowser dependant on IE version?
相关文章
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- Bundling the Windows Mono runtime with an applicat
- Windows 8.1 How to fix this obsolete code?
- Compile and build with single command line Java (L
- CosmosDB emulator can't start since port is al
- How to print to stdout from Python script with .py
I know I'm a little late to the party, but I thought I might contribute my subjectively more graceful solution.
I was looking for a script that would empty the Recycle Bin with an API call, rather than crudely deleting all files and folders from the filesystem. Having failed in my attempts to
RecycleBinObject.InvokeVerb("Empty Recycle &Bin")
(which apparently only works in XP or older), I stumbled upon discussions of using a function embedded in shell32.dll calledSHEmptyRecycleBin()
from a compiled language. I thought, hey, I can do that in PowerShell and wrap it in a batch script hybrid.Save this with a .bat extension and run it to empty your Recycle Bin. Run it with a
/y
switch to skip the confirmation.Here's a more complex version which first invokes
SHQueryRecycleBin()
to determine whether the bin is already empty prior to invokingSHEmptyRecycleBin()
. For this one, I got rid of thechoice
confirmation and/y
switch.Yes, you can Make a Batch file with the following code:
This basically creates a powershell script that empties the trash in the \Desktop directory, then runs it.
I use this powershell oneliner:
Works for different drives than C:, too
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..)It also has many more uses and options (output listed is from /?).
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: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.