Discussion:
Need to delete files in the RECYCLER bin deleted older then a certain date
(too old to reply)
Chris McKean
2007-10-25 15:33:11 UTC
Permalink
For deleting files from anywhere else, I can just use the "datalastmodified"
property to tell if a file is old enough for me to decide to delete. I was
hoping there was a property for the date the file was deleted, like called
"datedeleted" or something, but I can't find any documentation on that, or
method to achieve this some other way. Anyone have an idea?
Chris McKean
2007-10-25 17:03:53 UTC
Permalink
oops, typo, I meant "datelastmodified"...
Post by Chris McKean
For deleting files from anywhere else, I can just use the
"datalastmodified" property to tell if a file is old enough for me to
decide to delete. I was hoping there was a property for the date the file
was deleted, like called "datedeleted" or something, but I can't find any
documentation on that, or method to achieve this some other way. Anyone
have an idea?
Paul Randall
2007-10-25 19:11:04 UTC
Permalink
I was hoping there was a property for the date the file was deleted, like
called "datedeleted" or something
Maybe I don't understand what you want. If a file was deleted, what object
would hold this datedeleted property?

-Paul Randall
Chris McKean
2007-10-25 21:39:20 UTC
Permalink
Well, here's the scenario:
We are trying to conserve space on our server. Each user's "MyDocuments" is
on there, so a recycle bin for it is there, which is desired. But, we have
people sometimes not emptying their recycle bin for the many reasons that
exist. So, our ideal thought is that of doing the permanent delete of files
that have been in the recycle bin for greater then 'x' number of days...
You can see the column "Date Deleted" in Windows Explorer when you open the
recycle bin.... I just need some way of getting that piece of info...
Post by Paul Randall
I was hoping there was a property for the date the file was deleted, like
called "datedeleted" or something
Maybe I don't understand what you want. If a file was deleted, what
object would hold this datedeleted property?
-Paul Randall
Paul Randall
2007-10-26 00:33:26 UTC
Permalink
I haven't played with this much, but I think it is doable. I think you can
instantiate a shell folder object (different from a file system folder
object) for the recycle bin namespace, and then use getdetailsof property to
get the info you need for each file in this shell folder object. I don't
have any sample code, but there are two posting I found that might help.
Use Groups.google.com and paste the following in its search box:
getdetailsof recycle group:*.scripting

Hopefully someone else has more info and perhaps some sample code.
If you get it working, post the code so others can google it.

-Paul Randall
Post by Chris McKean
We are trying to conserve space on our server. Each user's "MyDocuments"
is on there, so a recycle bin for it is there, which is desired. But, we
have people sometimes not emptying their recycle bin for the many reasons
that exist. So, our ideal thought is that of doing the permanent delete of
files that have been in the recycle bin for greater then 'x' number of
days...
You can see the column "Date Deleted" in Windows Explorer when you open
the recycle bin.... I just need some way of getting that piece of info...
Post by Paul Randall
I was hoping there was a property for the date the file was deleted,
like called "datedeleted" or something
Maybe I don't understand what you want. If a file was deleted, what
object would hold this datedeleted property?
-Paul Randall
Paul Randall
2007-10-26 01:54:56 UTC
Permalink
Here is a sample script that should get you started:

Const RECYCLE_BIN = &Ha&

Dim objShell: Set objShell = _
CreateObject("Shell.Application")
Dim objShellFolder: Set objShellFolder = _
objShell.Namespace(RECYCLE_BIN)

Dim arrHeaders(33), i
For i = 0 to 33
arrHeaders(i) = i & vbTab & _
objShellFolder.GetDetailsOf(objShellFolder.Items, i)
Next
MsgBox Join(arrHeaders, vbCrLf)

Post if you need more help.

-Paul Randall
Post by Chris McKean
We are trying to conserve space on our server. Each user's "MyDocuments"
is on there, so a recycle bin for it is there, which is desired. But, we
have people sometimes not emptying their recycle bin for the many reasons
that exist. So, our ideal thought is that of doing the permanent delete of
files that have been in the recycle bin for greater then 'x' number of
days...
You can see the column "Date Deleted" in Windows Explorer when you open
the recycle bin.... I just need some way of getting that piece of info...
Post by Paul Randall
I was hoping there was a property for the date the file was deleted,
like called "datedeleted" or something
Maybe I don't understand what you want. If a file was deleted, what
object would hold this datedeleted property?
-Paul Randall
Chris McKean
2007-10-26 18:38:28 UTC
Permalink
But how do I get the names of the file and get the date they were deleted? I
have a feeling I need to really learn some overall vbscript to do this... I
saw code to it in Delphi, but it'd be nice if I didn't have to convince my
firm to buy a copy of that just for this :)
Post by Paul Randall
Const RECYCLE_BIN = &Ha&
Dim objShell: Set objShell = _
CreateObject("Shell.Application")
Dim objShellFolder: Set objShellFolder = _
objShell.Namespace(RECYCLE_BIN)
Dim arrHeaders(33), i
For i = 0 to 33
arrHeaders(i) = i & vbTab & _
objShellFolder.GetDetailsOf(objShellFolder.Items, i)
Next
MsgBox Join(arrHeaders, vbCrLf)
Post if you need more help.
-Paul Randall
Post by Chris McKean
We are trying to conserve space on our server. Each user's "MyDocuments"
is on there, so a recycle bin for it is there, which is desired. But, we
have people sometimes not emptying their recycle bin for the many reasons
that exist. So, our ideal thought is that of doing the permanent delete
of files that have been in the recycle bin for greater then 'x' number of
days...
You can see the column "Date Deleted" in Windows Explorer when you open
the recycle bin.... I just need some way of getting that piece of info...
Post by Paul Randall
I was hoping there was a property for the date the file was deleted,
like called "datedeleted" or something
Maybe I don't understand what you want. If a file was deleted, what
object would hold this datedeleted property?
-Paul Randall
Paul Randall
2007-10-26 19:13:27 UTC
Permalink
Hi, Chris
I played with the script a little more.

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
For Each strFileName in objShellFolder.Items
sMsg = ""
'Get the info associated with each description
For i = 0 to 33
sMsg = sMsg & arrHeaders(i) & _
": " & objShellFolder.GetDetailsOf(strFileName, i) & vbCrLf
Next

iResponse = MsgBox(sMsg, 1)
If iResponse = 2 Then WScript.Quit
Next

I'm sure Microsoft has the object model for the shell object documented
somewhere, but I can't find it.

This line gets the item names. They might be file items or folder items --
whatever is in the recycle bin.:
For Each strFileName in objShellFolder.Items

The items are actually objects, but the default property for them is their
name, so strFileName cycles through all the items (who knows, Vista might
have more kinds of items than just file and folder items in its recycle bin,
like junction points?) and contains just the name of that item.

-Paul Randall
Post by Chris McKean
But how do I get the names of the file and get the date they were deleted?
I have a feeling I need to really learn some overall vbscript to do
this... I saw code to it in Delphi, but it'd be nice if I didn't have to
convince my firm to buy a copy of that just for this :)
Post by Paul Randall
Const RECYCLE_BIN = &Ha&
Dim objShell: Set objShell = _
CreateObject("Shell.Application")
Dim objShellFolder: Set objShellFolder = _
objShell.Namespace(RECYCLE_BIN)
Dim arrHeaders(33), i
For i = 0 to 33
arrHeaders(i) = i & vbTab & _
objShellFolder.GetDetailsOf(objShellFolder.Items, i)
Next
MsgBox Join(arrHeaders, vbCrLf)
Post if you need more help.
-Paul Randall
Post by Chris McKean
We are trying to conserve space on our server. Each user's "MyDocuments"
is on there, so a recycle bin for it is there, which is desired. But, we
have people sometimes not emptying their recycle bin for the many
reasons that exist. So, our ideal thought is that of doing the permanent
delete of files that have been in the recycle bin for greater then 'x'
number of days...
You can see the column "Date Deleted" in Windows Explorer when you open
the recycle bin.... I just need some way of getting that piece of info...
Post by Paul Randall
I was hoping there was a property for the date the file was deleted,
like called "datedeleted" or something
Maybe I don't understand what you want. If a file was deleted, what
object would hold this datedeleted property?
-Paul Randall
Chris McKean
2007-10-29 14:39:37 UTC
Permalink
Hmm, time to buy a book I guess...
Post by Paul Randall
Hi, Chris
I played with the script a little more.
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
For Each strFileName in objShellFolder.Items
sMsg = ""
'Get the info associated with each description
For i = 0 to 33
sMsg = sMsg & arrHeaders(i) & _
": " & objShellFolder.GetDetailsOf(strFileName, i) & vbCrLf
Next
iResponse = MsgBox(sMsg, 1)
If iResponse = 2 Then WScript.Quit
Next
I'm sure Microsoft has the object model for the shell object documented
somewhere, but I can't find it.
This line gets the item names. They might be file items or folder
For Each strFileName in objShellFolder.Items
The items are actually objects, but the default property for them is their
name, so strFileName cycles through all the items (who knows, Vista might
have more kinds of items than just file and folder items in its recycle
bin, like junction points?) and contains just the name of that item.
-Paul Randall
Post by Chris McKean
But how do I get the names of the file and get the date they were
deleted? I have a feeling I need to really learn some overall vbscript to
do this... I saw code to it in Delphi, but it'd be nice if I didn't have
to convince my firm to buy a copy of that just for this :)
Post by Paul Randall
Const RECYCLE_BIN = &Ha&
Dim objShell: Set objShell = _
CreateObject("Shell.Application")
Dim objShellFolder: Set objShellFolder = _
objShell.Namespace(RECYCLE_BIN)
Dim arrHeaders(33), i
For i = 0 to 33
arrHeaders(i) = i & vbTab & _
objShellFolder.GetDetailsOf(objShellFolder.Items, i)
Next
MsgBox Join(arrHeaders, vbCrLf)
Post if you need more help.
-Paul Randall
Post by Chris McKean
We are trying to conserve space on our server. Each user's
"MyDocuments" is on there, so a recycle bin for it is there, which is
desired. But, we have people sometimes not emptying their recycle bin
for the many reasons that exist. So, our ideal thought is that of doing
the permanent delete of files that have been in the recycle bin for
greater then 'x' number of days...
You can see the column "Date Deleted" in Windows Explorer when you open
the recycle bin.... I just need some way of getting that piece of info...
Post by Paul Randall
I was hoping there was a property for the date the file was deleted,
like called "datedeleted" or something
Maybe I don't understand what you want. If a file was deleted, what
object would hold this datedeleted property?
-Paul Randall
Paul Randall
2007-10-29 16:30:37 UTC
Permalink
Your reply is not very helpful. What do you get when you run the script?
On my WXP SP2 system with IE6, my first message box shows something like:

0 Name: dvdsig.md5
1 Original Location: C:\VISTAG\D1
2 Date Deleted: 3/20/2007 6:54 PM
3 Size: 32 KB
4 Type: MD5 File
5 Date Modified: 3/20/2007 6:02 PM
6 Date Created: 3/20/2007 5:59 PM
7 Date Accessed: 3/20/2007 12:00 AM
8 Attributes: A
9 Status: Online
10 Owner: Everyone
11 Author:
12 Title:
13 Subject:
14 Category:
15 Pages:
16 Comments:
17 Copyright:
18 Artist:
19 Album Title:
20 Year:
21 Track Number:
22 Genre:
23 Duration:
24 Bit Rate:
25 Protected:
26 Camera Model:
27 Date Picture Taken:
28 Dimensions:
29 :
30 :
31 Episode Name:
32 Program Description:
33 :

---------------------------
OK Cancel
---------------------------

I suppose different versions of Windows/Internet Explorer will produce
different results. For my system, it is pretty obvious that while looping
through the array of folder items (the files and folders in the recycle
Post by Chris McKean
Post by Paul Randall
For Each strFileName in objShellFolder.Items
when I get to the file whose name is:
dvdsig.md5, and I loop through the 34 possible indexing values for folder
item properties (I suppose there may be more values, but sample code I've
come across seldom mentioned the possibility of more),when 'i' has a value
of 2, then
Post by Chris McKean
Post by Paul Randall
objShellFolder.GetDetailsOf(objShellFolder.Items, i)
returns the description of item 'i', which is "date deleted". And
Post by Chris McKean
Post by Paul Randall
objShellFolder.GetDetailsOf(strFileName, i)
returns the actual date, a value of "3/20/2007 6:54 PM".
Yes, I have not emptied my recycle bin for over six months.

It seems to me it should be easy to use VBScript's DateDiff function to
determine how long it has been since the file was deleted from its original
position and put in the Recycle Bin.

Then all you have left is to figure out how to remove the item from the
Recycle Bin. I think you would use the filesystem object for that, but I'm
not sure.

Of course, if you have an older OS, my script may have given you garbage.
http://groups.google.com/group/microsoft.public.scripting.vbscript/tree/browse_frm/thread/1b2c8dd240905715/bdba5d3e21382ba7?rnum=1&q=%22delete+from%22+recycle+bin+group%3A*.scripting.vbscript&_done=%2Fgroup%2Fmicrosoft.public.scripting.vbscript%2Fbrowse_frm%2Fthread%2F1b2c8dd240905715%2Ff21c1f3ef091823e%3Flnk%3Dst%26q%3D%2522delete%2Bfrom%2522%2Brecycle%2Bbin%2Bgroup%253A*.scripting.vbscript%26#doc_f21c1f3ef091823e

And Vista may be different too. In any case, a book can help you to
understand the structure and syntax of VBScript, but I doubt that you will
find one that delves into the shell object and the getdetailsof property of
shell folder items. This morning I came across this link which can lead you
to lots of info but few examples of how it can be used in VBScript:
http://msdn2.microsoft.com/en-us/library/bb787868.aspx

I'm willing to help if you provide enough feedback so I know what progress
you are making.

-Paul Randall
Post by Chris McKean
Hmm, time to buy a book I guess...
Post by Paul Randall
Hi, Chris
I played with the script a little more.
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
For Each strFileName in objShellFolder.Items
sMsg = ""
'Get the info associated with each description
For i = 0 to 33
sMsg = sMsg & arrHeaders(i) & _
": " & objShellFolder.GetDetailsOf(strFileName, i) & vbCrLf
Next
iResponse = MsgBox(sMsg, 1)
If iResponse = 2 Then WScript.Quit
Next
I'm sure Microsoft has the object model for the shell object documented
somewhere, but I can't find it.
This line gets the item names. They might be file items or folder
For Each strFileName in objShellFolder.Items
The items are actually objects, but the default property for them is
their name, so strFileName cycles through all the items (who knows, Vista
might have more kinds of items than just file and folder items in its
recycle bin, like junction points?) and contains just the name of that
item.
-Paul Randall
Post by Chris McKean
But how do I get the names of the file and get the date they were
deleted? I have a feeling I need to really learn some overall vbscript
to do this... I saw code to it in Delphi, but it'd be nice if I didn't
have to convince my firm to buy a copy of that just for this :)
Post by Paul Randall
Const RECYCLE_BIN = &Ha&
Dim objShell: Set objShell = _
CreateObject("Shell.Application")
Dim objShellFolder: Set objShellFolder = _
objShell.Namespace(RECYCLE_BIN)
Dim arrHeaders(33), i
For i = 0 to 33
arrHeaders(i) = i & vbTab & _
objShellFolder.GetDetailsOf(objShellFolder.Items, i)
Next
MsgBox Join(arrHeaders, vbCrLf)
Post if you need more help.
-Paul Randall
Post by Chris McKean
We are trying to conserve space on our server. Each user's
"MyDocuments" is on there, so a recycle bin for it is there, which is
desired. But, we have people sometimes not emptying their recycle bin
for the many reasons that exist. So, our ideal thought is that of
doing the permanent delete of files that have been in the recycle bin
for greater then 'x' number of days...
You can see the column "Date Deleted" in Windows Explorer when you
open the recycle bin.... I just need some way of getting that piece of
info...
Post by Paul Randall
I was hoping there was a property for the date the file was deleted,
like called "datedeleted" or something
Maybe I don't understand what you want. If a file was deleted, what
object would hold this datedeleted property?
-Paul Randall
Chris McKean
2007-10-29 19:13:21 UTC
Permalink
Sorry, 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...
Post by Paul Randall
Your reply is not very helpful. What do you get when you run the script?
0 Name: dvdsig.md5
1 Original Location: C:\VISTAG\D1
2 Date Deleted: 3/20/2007 6:54 PM
3 Size: 32 KB
4 Type: MD5 File
5 Date Modified: 3/20/2007 6:02 PM
6 Date Created: 3/20/2007 5:59 PM
7 Date Accessed: 3/20/2007 12:00 AM
8 Attributes: A
9 Status: Online
10 Owner: Everyone
---------------------------
OK Cancel
---------------------------
I suppose different versions of Windows/Internet Explorer will produce
different results. For my system, it is pretty obvious that while looping
through the array of folder items (the files and folders in the recycle
Post by Chris McKean
Post by Paul Randall
For Each strFileName in objShellFolder.Items
dvdsig.md5, and I loop through the 34 possible indexing values for folder
item properties (I suppose there may be more values, but sample code I've
come across seldom mentioned the possibility of more),when 'i' has a value
of 2, then
Post by Chris McKean
Post by Paul Randall
objShellFolder.GetDetailsOf(objShellFolder.Items, i)
returns the description of item 'i', which is "date deleted". And
Post by Chris McKean
Post by Paul Randall
objShellFolder.GetDetailsOf(strFileName, i)
returns the actual date, a value of "3/20/2007 6:54 PM".
Yes, I have not emptied my recycle bin for over six months.
It seems to me it should be easy to use VBScript's DateDiff function to
determine how long it has been since the file was deleted from its
original position and put in the Recycle Bin.
Then all you have left is to figure out how to remove the item from the
Recycle Bin. I think you would use the filesystem object for that, but
I'm not sure.
Of course, if you have an older OS, my script may have given you garbage.
http://groups.google.com/group/microsoft.public.scripting.vbscript/tree/browse_frm/thread/1b2c8dd240905715/bdba5d3e21382ba7?rnum=1&q=%22delete+from%22+recycle+bin+group%3A*.scripting.vbscript&_done=%2Fgroup%2Fmicrosoft.public.scripting.vbscript%2Fbrowse_frm%2Fthread%2F1b2c8dd240905715%2Ff21c1f3ef091823e%3Flnk%3Dst%26q%3D%2522delete%2Bfrom%2522%2Brecycle%2Bbin%2Bgroup%253A*.scripting.vbscript%26#doc_f21c1f3ef091823e
And Vista may be different too. In any case, a book can help you to
understand the structure and syntax of VBScript, but I doubt that you will
find one that delves into the shell object and the getdetailsof property
of shell folder items. This morning I came across this link which can
lead you to lots of info but few examples of how it can be used in
http://msdn2.microsoft.com/en-us/library/bb787868.aspx
I'm willing to help if you provide enough feedback so I know what progress
you are making.
-Paul Randall
Post by Chris McKean
Hmm, time to buy a book I guess...
Post by Paul Randall
Hi, Chris
I played with the script a little more.
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
For Each strFileName in objShellFolder.Items
sMsg = ""
'Get the info associated with each description
For i = 0 to 33
sMsg = sMsg & arrHeaders(i) & _
": " & objShellFolder.GetDetailsOf(strFileName, i) & vbCrLf
Next
iResponse = MsgBox(sMsg, 1)
If iResponse = 2 Then WScript.Quit
Next
I'm sure Microsoft has the object model for the shell object documented
somewhere, but I can't find it.
This line gets the item names. They might be file items or folder
For Each strFileName in objShellFolder.Items
The items are actually objects, but the default property for them is
their name, so strFileName cycles through all the items (who knows,
Vista might have more kinds of items than just file and folder items in
its recycle bin, like junction points?) and contains just the name of
that item.
-Paul Randall
Post by Chris McKean
But how do I get the names of the file and get the date they were
deleted? I have a feeling I need to really learn some overall vbscript
to do this... I saw code to it in Delphi, but it'd be nice if I didn't
have to convince my firm to buy a copy of that just for this :)
Post by Paul Randall
Const RECYCLE_BIN = &Ha&
Dim objShell: Set objShell = _
CreateObject("Shell.Application")
Dim objShellFolder: Set objShellFolder = _
objShell.Namespace(RECYCLE_BIN)
Dim arrHeaders(33), i
For i = 0 to 33
arrHeaders(i) = i & vbTab & _
objShellFolder.GetDetailsOf(objShellFolder.Items, i)
Next
MsgBox Join(arrHeaders, vbCrLf)
Post if you need more help.
-Paul Randall
Post by Chris McKean
We are trying to conserve space on our server. Each user's
"MyDocuments" is on there, so a recycle bin for it is there, which is
desired. But, we have people sometimes not emptying their recycle bin
for the many reasons that exist. So, our ideal thought is that of
doing the permanent delete of files that have been in the recycle bin
for greater then 'x' number of days...
You can see the column "Date Deleted" in Windows Explorer when you
open the recycle bin.... I just need some way of getting that piece
of info...
Post by Paul Randall
I was hoping there was a property for the date the file was
deleted, like called "datedeleted" or something
Maybe I don't understand what you want. If a file was deleted, what
object would hold this datedeleted property?
-Paul Randall
Paul Randall
2007-10-29 22:14:20 UTC
Permalink
OK, I've made some more changes.
Note in particular, the old line
Post by Paul Randall
For 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 Randall
Sorry, 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...
Chris McKean
2007-11-02 12:10:04 UTC
Permalink
This is awesome man, sorry I haven't been back to this in a while... I'm
seeing about getting datediff working with it....
Post by Paul Randall
OK, I've made some more changes.
Note in particular, the old line
Post by Paul Randall
For 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
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 Randall
Sorry, 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...
Chris McKean
2007-11-05 15:16:35 UTC
Permalink
So the datediff bit works... As far as the confimation boxes go, I figure
what I'll do, is find how to uncheck "Display delete confirmation dialog" at
the top of this script, and then enable it at the end. At worst, someone
will just not be prompted for confirmation for something to go into the
recycle bin yeah? Though if I make this run on login (through Microsoft
SMS), then the script will have run before the user will be even doing any
activity...what do you think? Kinda dodgy.. but if there's no verb
"DeleteWithoutConfirmation", it seems like the way to go :)
Post by Chris McKean
This is awesome man, sorry I haven't been back to this in a while... I'm
seeing about getting datediff working with it....
Post by Paul Randall
OK, I've made some more changes.
Note in particular, the old line
Post by Paul Randall
For 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
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 Randall
Sorry, 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...
Paul Randall
2007-11-05 16:16:54 UTC
Permalink
Hi, Chris
I'm glad to hear that you are making progress. Hopefully you can find what
you want to get rid of that confirmation. I don't mess with login scripts,
so I can't help you with that.

In the past I've used SendKeys to dismiss confirmations like that, but I
find SendKeys unreliable because it is so easy for some process to make its
window active and the keys get sent to the wrong window. To get around that
problem, I occasionally use the free utility AutoIt. This can be used as a
COM object and reliably sends keystrokes to specific windows, as well as
mouse movements and clicks.
http://www.autoitscript.com/autoit3/

Now that you know how to look at the contents of the recycle bin with the
shell object, which gives original info about deleted files, such as its
original name and location and size, perhaps you should look at the recycle
bin folders on each hard drive with the file system object. The names have
been changed here, but you may find that the file date is useful for your
purposes and you may be able to use the file system object to delete files
and folders with no confirmation. FSO file sizes don't match the shell file
sizes because within the recycle bin they are compressed -- why waste space
on deleted files?

Access C: drive's recycle bin with:
Set objFolder = objFSo.GetFolder("c:\Recycled")

-Paul Randall
Post by Chris McKean
So the datediff bit works... As far as the confimation boxes go, I figure
what I'll do, is find how to uncheck "Display delete confirmation dialog" at
the top of this script, and then enable it at the end. At worst, someone
will just not be prompted for confirmation for something to go into the
recycle bin yeah? Though if I make this run on login (through Microsoft
SMS), then the script will have run before the user will be even doing any
activity...what do you think? Kinda dodgy.. but if there's no verb
"DeleteWithoutConfirmation", it seems like the way to go :)
Post by Chris McKean
This is awesome man, sorry I haven't been back to this in a while... I'm
seeing about getting datediff working with it....
Post by Paul Randall
OK, I've made some more changes.
Note in particular, the old line
Post by Paul Randall
For 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
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 Randall
Sorry, 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...
Loading...