通常人们使用Shell32.dll
获取回收站内的文件列表。
private static IEnumerable<string> GetRecycleBinFilenames()
{
const int ssfBitbucket = 10;
Type t = Type.GetTypeFromProgID("Shell.Application");
dynamic shell = Activator.CreateInstance(t);
Folder recycleBin = shell.NameSpace(ssfBitbucket);
foreach (FolderItem2 recfile in recycleBin.Items())
{
yield return recfile.Path;
}
Marshal.FinalReleaseComObject(shell);
}
我正在装载 VHDX 文件,并希望从已装载的外部磁盘/卷上的回收站获取文件列表。我怎样才能做到这一点?
最佳答案
如@RaymondChen suggested您可以根据 Path
property 进行过滤,其中包含已删除项目的当前路径...
foreach (FolderItem2 recfile in recycleBin.Items())
{
if (Path.GetPathRoot(recfile.Path) == "X:\\")
yield return recfile.Path;
}
您还可以检索删除项目的目录路径并以相同的方式进行过滤...
const int BitBucketItem_OriginalParentPath = 1;
foreach (FolderItem2 recfile in recycleBin.Items())
{
string originalParentPath = recycleBin.GetDetailsOf(recfile, BitBucketItem_OriginalParentPath);
if (Path.GetPathRoot(originalParentPath) == "X:\\")
yield return recfile.Path;
}
...但是,如果通过结点/符号链接(symbolic link)删除该项目,则 originalParentPath
将包含结点/符号链接(symbolic link)的驱动器,该驱动器不一定是存储已删除项目的驱动器。
关于c# - 如何从回收站获取已安装卷/磁盘的文件列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37169214/