2

更新 2

最后测试了WindowsAPICodePack我自己发现的大多数接口访问回收站上已删除文件的方法。

现在唯一的问题是我需要知道如何访问所需的属性包来检索每个文件(以及文件夹和链接)的删除日期,这是一个示例代码:

Dim RecycleBin As IKnownFolder = KnownFolders.RecycleBin

For Each File As ShellFile In (From Item As ShellObject In RecycleBin
                               Where Item.GetType = GetType(ShellFile))

    MsgBox(File.Name)
    MsgBox(File.Properties.System.IsDeleted.Value) ' It's empty.
    MsgBox(File.Properties.System.DateAcquired.Value) ' This is not the correct value.
    MsgBox(File.Properties.System.DateArchived.Value) ' This is also not the correct value.
    MsgBox(File.Properties.System.DateCompleted.Value) ' This is also not the correct value.
    MsgBox(File.Properties.System.DateCreated.Value) ' This is also not the correct value.
    MsgBox(File.Properties.System.DateImported.Value) ' This is also not the correct value.

Next File
4

2 回答 2

2

Windows API 代码包可能对您有所帮助。它具有大多数 shell 接口的更广泛(完整)的实现。您必须打开代码包项(InternalsVisibleTo 应用程序清单属性,或者只是将所有内部接口更改为外部接口)才能在给定包装器之外使用它们。

至于删除日期:包含在shell项的属性包中。
伟大的 Raymond Chen,从一开始就是微软的一名开发人员,并亲自创造了 Windows Shell,他写了一篇关于如何在 C++ 中进行操作的完整演练文章,恰如其分地命名为“我如何获取信息”关于回收站中的物品?'

您可以通过一点逻辑推论,从中取出您需要的部分并生成您自己的托管实现。

在这两个链接之间,您现在拥有解决问题的所有知识,然后是一些知识。

于 2014-01-07T19:17:25.393 回答
2

检索DateDeletedItem 的属性很简单,如下所示:

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
于 2014-01-17T18:59:27.897 回答