检索DateDeleted
Item 的属性很简单,如下所示:
Private Sub Test() Handles MyBase.Shown
' Get all the desired deleted items inside the Recycle Bin using WindowsAPICodePack.
' ( In my case I only retrieve the deleted files excluding folders. )
Dim RecycledFiles As ShellFile() = RecycleBin.MasterBin.Files
' Loop through the deleted Items.
For Each Item As ShellFile In RecycledFiles
' Append the full name
sb.AppendLine(Item.Name)
' Append the DateDeleted.
sb.AppendLine(Item.Properties.GetProperty("DateDeleted").ValueAsObject.ToString)
MsgBox(sb.ToString)
sb.Clear()
Next Item
End Sub
然后检索最后删除的文件,例如:
''' <summary>
''' Gets the last deleted file inside recycle bin.
''' </summary>
''' <returns>ShellFile.</returns>
Public Shared Function GetLastDeletedFile() As ShellFile
Return (From Item As ShellFile In GetDeletedItems(Of ShellFile)(Nothing)
Order By Item.Properties.GetProperty("DateDeleted").ValueAsObject).Last
End Function
使用此代码段,我们可以检索每个属性的其他属性名称和值:
Dim sb As New System.Text.StringBuilder
Private Sub Test() Handles MyBase.Shown
' Get all the desired deleted items inside the Recycle Bin using WindowsAPICodePack.
' ( In my case I only retrieve the deleted files excluding folders. )
Dim RecycledFiles As ShellFile() = RecycleBin.MasterBin.Files
' Loop through the deleted Items.
For Each Item As ShellFile In RecycledFiles
' Append the full name (It's String type)
sb.AppendLine(Item.Name)
' Loop through the Item properties.
For Each prop In Item.Properties.DefaultPropertyCollection
' Append an empty line
sb.AppendLine()
' Append the property name (It's String type)
sb.Append(prop.CanonicalName)
' Append the property value (It's a generic Object type)
If prop.ValueAsObject IsNot Nothing Then
sb.Append(" = " & prop.ValueAsObject.ToString)
Else
sb.Append(" = NULL")
End If
MsgBox(sb.ToString)
Next prop
Next Item
End Sub
再举一个例子:
Private Sub Test() Handles MyBase.Shown
' Get all the deleted items inside the Recycle Bin using WindowsAPICodePack.
Dim RecycledItems As ShellObject() = RecycleBin.MainBin.Items
' Loop through the deleted Items (Ordered by Deletion Date).
For Each Item As ShellFile In (From itm In RecycledItems
Order By itm.Properties.GetProperty("DateDeleted").ValueAsObject Ascending)
' Append the property bags information.
sb.AppendLine(String.Format("Full Name: {0}",
Item.Name))
sb.AppendLine(String.Format("Item Name: {0}",
Item.Properties.GetProperty("System.ItemNameDisplay").ValueAsObject))
sb.AppendLine(String.Format("Deleted From: {0}",
Item.Properties.GetProperty("DeletedFrom").ValueAsObject))
sb.AppendLine(String.Format("Item Type: {0}",
Item.Properties.GetProperty("System.ItemTypeText").ValueAsObject))
sb.AppendLine(String.Format("Item Size: {0}",
Item.Properties.GetProperty("System.Size").ValueAsObject))
sb.AppendLine(String.Format("Attributes: {0}",
[Enum].Parse(GetType(IO.FileAttributes),
Item.Properties.GetProperty("System.FileAttributes").ValueAsObject.ToString)))
sb.AppendLine(String.Format("Date Deleted: {0}",
Item.Properties.GetProperty("DateDeleted").ValueAsObject))
sb.AppendLine(String.Format("Date Modified: {0}",
Item.Properties.GetProperty("System.DateModified").ValueAsObject))
sb.AppendLine(String.Format("Date Created: {0}",
Item.Properties.GetProperty("System.DateCreated").ValueAsObject))
MsgBox(sb.ToString)
sb.Clear()
Next Item
End Sub