OK, I've made some more changes.
Note in particular, the old line
Post by Paul RandallFor Each strFileName in objShellFolder.Items
was misleading. It implied that strFileName is a string, and contains the
name of a file. That is not true. In fact, it is a shell folder item
object, so the line is now:
For Each objShellFolderItem in objShellFolder.Items
I've also made other changes, but this one is key.
If you right click on any file or folder in Windows Explorer, you will
probably be presented with a context menu with a list of things you can
choose to do related to that item. One of those things will probably be
'Delete'. If you consider the word or phrase to be a verb describing what
is to be done, then all we would need is an InvokeVerb method that we could
apply to a particular Shell Folder Item that you wanted to do something to.
Guess what objShellFolderItem.InvokeVerb("Delete") does?
The only bad thing is that a message box pops up requesting confirmation
that you really want to delete it. Sadly, you can have multiple items with
the same name in the recycle bin, that may have been deleted from the same
or different folders, and the confirmation message only tells its name, not
from where or when it was originally deleted. This won't matter to the
finished script.
I think only one problem remains - getting rid of the confirmation message.
Const RECYCLE_BIN = &hA&
Dim objShell: Set objShell = _
CreateObject("Shell.Application")
Dim objShellFolder: Set objShellFolder = _
objShell.Namespace(RECYCLE_BIN)
Dim arrHeaders(33), i
'Get the descriptions of available info
For i = 0 to 33
arrHeaders(i) = i & vbTab & _
objShellFolder.GetDetailsOf(objShellFolder.Items, i)
Next
'MsgBox Join(arrHeaders, vbCrLf)
Dim strFileName, iResponse, objShellFolderItem
For Each objShellFolderItem in objShellFolder.Items
strFileName = objShellFolderItem
MsgBox "Working on " & objShellFolderItem & vbCrLf & _
TypeName(objShellFolderItem) & vbCrLf & _
"FileName = " & strFileName
sMsg = ""
'Get the info associated with each description
For i = 0 to 33
sMsg = sMsg & arrHeaders(i) & _
": " & objShellFolder.GetDetailsOf(objShellFolderItem, i) & vbCrLf
Next
iResponse = MsgBox( _
"Do you want to delete this item from the Recycle Bin?" & vbCrLf & _
sMsg, 3)
If iResponse = 2 Then
MsgBox "Quitting - you clicked Cancel"
WScript.Quit
ElseIf iResponse = 7 Then
MsgBox "You ckicked No"
ElseIf iResponse = 6 Then
MsgBox "You clicked Yes" & vbCrLf & _
strFileName & " will now be deleted"
objShellFolderItem.InvokeVerb("Delete")
End If
Next
Post by Paul RandallSorry, I should of explained a bit better... I got the same results, but I
was still unable to find a way to get a file deleted from the recycle bin
with the previous code (i.e., so I figured I'd try to find a book, or
subscribe to whereever I might find more info on the object model, since I
was also unable to find any object model docs too).... but with the code
and ideas you just gave, I'll get back to you...