Option Explicit Dim colItems, objDesktop, objDtFldr, objFolder Dim objFSO, objMyDocsFolder, objMyDocuments Dim objProgFiles, objProgFolder Dim objShell, objWinDir, objWindows Dim i, strFolder, strProf Const MY_DOCUMENTS = &H5 Const DESKTOP = &H10 Const WINDOWS = &H24 Const PROGRAM_FILES = &H26 ' Parse command line With WScript.Arguments If .Unnamed.Count <> 1 Then Syntax If .Named.Count > 0 Then Syntax strFolder = Replace( .Unnamed(0), """", "" ) End With ' Open the Shell Folders object Set objShell = CreateObject( "Shell.Application" ) ' Check if a valid folder was specified Set objFSO = CreateObject( "Scripting.FileSystemObject" ) ' Folder should at least exist If Not objFSO.FolderExists( strFolder ) Then Syntax ' Skip root directories If Len( strFolder ) < 4 Then Syntax If objFSO.GetParentFolderName( strFolder ) = "" Then Syntax ' Skip the Windows directory Set objWindows = objShell.Namespace( WINDOWS ) Set objWinDir = objWindows.Self If InStr( 1, strFolder, objWinDir.Path, vbTextCompare ) Then Syntax Set objWinDir = Nothing Set objWindows = Nothing ' Skip Program Files folder Set objProgFiles = objShell.Namespace( PROGRAM_FILES ) Set objProgFolder = objProgFiles.Self If InStr( 1, strFolder, objProgFolder.Path, vbTextCompare ) Then Syntax Set objProgFolder = Nothing Set objProgFolder = Nothing ' Skip My Documents Set objMyDocuments = objShell.Namespace( MY_DOCUMENTS ) Set objMyDocsFolder = objMyDocuments.Self If InStr( 1, strFolder, objMyDocsFolder.Path, vbTextCompare ) Then Syntax Set objMyDocsFolder = Nothing Set objMyDocuments = Nothing ' Skip profiles Set objDesktop = objShell.Namespace( DESKTOP ) Set objDtFldr = objDesktop.Self strProf = objFSO.GetParentFolderName( objFSO.GetParentFolderName( objDtFldr.Path ) ) If InStr( 1, strFolder, strProf, vbTextCompare ) Then Syntax Set objDtFldr = Nothing Set objDesktop = Nothing Set objFSO = Nothing ' Create an object for the specified folder Set objFolder = objShell.Namespace( strFolder ) Set colItems = objFolder.Items ' Delete everything in the specified folder If colItems.Count > 0 Then colItems.InvokeVerbEx( "Delete" ) End If Sub Syntax Dim strMsg strMsg = "Recycle.vbs, Version 1.10" _ & vbCrLf _ & "Move the contents of a folder to the Recycle Bin" _ & vbCrLf & vbCrLf _ & "Usage: " & UCase( WScript.ScriptName ) & " folder_path" _ & vbCrLf & vbCrLf _ & "Where: folder_path specifies the folder to be purged" _ & vbCrLf & vbCrLf _ & "Note: Deleting root directories, profile folders, the Program Files or" _ & vbCrLf _ & " Windows folder or My Documents is not allowed." _ & vbCrLf & vbCrLf _ & "Written by Rob van der Woude" _ & vbCrLf _ & "http://www.robvanderwoude.com" WScript.Echo strMsg WScript.Quit 1 End Sub