Board index » Visual Studio » Empty Recycle Bin

Empty Recycle Bin

Visual Studio1
I can display the files in the Recycle Bin for the user but would like

to empty it. The code below "reports file not found" using the

deletefile method. Is there a better way?



----------------

Const RECYCLE_BIN = &Ha&



Set objShell = CreateObject("Shell.Application")

Set objFolder = objShell.Namespace(RECYCLE_BIN)

Set objFolderItem = objFolder.Self

Set objFSO = CreateObject("Scripting.FileSystemObject")



WScript.Echo "Recycle Bin Location: " & objFolderItem.Path

WScript.Echo "Files in Recycle Bin"

WScript.Echo "--------------------"

Set colItems = objFolder.Items

For Each objItem in colItems

Wscript.Echo objItem.Name

Next

WScript.Echo VbCrLf & "Deleting Files in Recycle Bin"

For Each objItem in colItems

objFSO.DeleteFile(objFolderItem.Path & "\" & objItem.Name)

Next

WScript.Echo VbCrLf & "Files NOW in Recycle Bin"

WScript.Echo "------------------------"

For Each objItem in colItems

Wscript.Echo objItem.Name

Next

----------------


-
 

Re:Empty Recycle Bin

Dale wrote:



Quote
I can display the files in the Recycle Bin for the user but would like

to empty it. The code below "reports file not found" using the

deletefile method. Is there a better way?

Hi



You can't use the DeleteFile method in Scripting.FileSystemObject to

delete files in the Recycle Bin.



A couple of other alternatives:



1)

Using the Shell.Application object from VBScript

(InvokeVerb "Empty Recycle &Bin"):

http://groups.google.co.uk/groups?selm" rel="nofollow" target="_blank">groups.google.co.uk/groups=3CAC1E44.9E9CD575%40hydro.com





2)

The free command line tool EmptyRecycleBin.exe should help you

here as well (using the /Q command line switch).



Download it from

www.optimumx.com/download/">www.optimumx.com/download/







--

torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway

Administration scripting examples and an ONLINE version of

the 1328 page Scripting Guide:

www.microsoft.com/technet/scriptcenter/default.mspx">www.microsoft.com/technet/scriptcenter/default.mspx

-