Friday, February 10, 2017

VBScript Empty Recycle Bin

VBScript is a scripting language to manage computer developed by Microsoft. Now it is easy to empty your recycle bin easily. Below is a code snippet that describe how recycle bin be empty.

Const RECYCLE_BIN = &Ha&

Set FSO = CreateObject("Scripting.FileSystemObject")
Set ObjShell = CreateObject("Shell.Application")
Set ObjFolder = ObjShell.Namespace(RECYCLE_BIN)
Set ObjFolderItem = ObjFolder.Self
Wscript.Echo ObjFolderItem.Path

Set colItems = ObjFolder.Items
For Each objItem in colItems
    Wscript.Echo objItem.Name
    If (objItem.Type = "File folder") Then
        FSO.DeleteFolder(objItem.Path)
    Else
        FSO.DeleteFile(objItem.Path)
    End If
Next

1 comment: