我参考了这篇文章如何检索'删除日期'属性存储在回收站中的项目使用Windows API代码包?
我参考了@ElektroStudios的答案。我正在试着运行那个代码。我对VB.net的了解很少。
Imports Microsoft.WindowsAPICodePack.Shell
Imports System.Text
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim RecycledFiles As ShellFile() = RecycleBin.MasterBin.Files
Dim sb As StringBuilder
' 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
End Class
然而,我得到一个编译器错误,RecycleBin is not declared
。在
RecycleBin.MasterBin.Files
我不太确定如何使这项工作。我在这里漏掉了什么?这是正确的代码吗?我是否遗漏了任何导入或引用?
我已经安装了
nugetInstall-Package WindowsAPICodePack-Core
nugetInstall-Package WindowsAPICodePack-Shell
注意-我已经使用
成功访问了RecycleBinSH.NameSpace(Shell32.ShellSpecialFolderConstants.ssfBITBUCKET)
我对上面那段代码特别感兴趣。由于
要获取回收站中项目的删除日期,您不需要任何额外的库,您可以使用Shell对象脚本和Microsoft Visual Basic库(我知道您已经在最后几句中找到了)和ExtendedProperty方法。
下面是一些代码,用于转储回收站中的项目及其删除日期:
Sub Main()
Dim shell = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"))
Const ssfBITBUCKET As Integer = 10
Dim folder = shell.Namespace(ssfBITBUCKET)
For Each item In folder.Items
' dump some standard properties
Console.WriteLine(item.Path)
Console.WriteLine(item.ModifyDate)
' dump extended properties (note they are typed, here as a Date)
Dim dd As Date = item.ExtendedProperty("DateDeleted")
Console.WriteLine(dd)
' same but using the "canonical name"
' see https://learn.microsoft.com/en-us/windows/win32/api/propsys/nf-propsys-psgetpropertydescriptionbyname#remarks
Console.WriteLine(item.ExtendedProperty("System.Recycle.DateDeleted"))
Next
End Sub