如何获得回收站的路径? [英] How can I get path to recycle bin?

查看:445
本文介绍了如何获得回收站的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得回收站的路径.我在网上搜索,发现人们使用shell32并在回收站中获取文件列表.但是,我只想获取回收站的路径,因为我的目的是在将IncludeSubdirectories设置为true时从文件监视程序中排除监视器回收站.使用shell32来获取文件列表的代码如下所示,但我不了解如何获取回收站的路径.

I would like to get the path to recycle bin. I searched online and found people use shell32 and get a list of files in recycle bin. However, I only want to get the path of recycle bin since my purpose is to exclude monitor recycle bin from my filewatcher when setting IncludeSubdirectories to true. The code using shell32 to get a list of files shown in the following, but I don't to how to get the path to recycle bin.

Shell Shl = new Shell();
Folder Recycler = Shl.NameSpace(10);
for (int i = 0; i < Recycler.Items().Count; i++)
{
    FolderItem FI = Recycler.Items().Item(i);
    string FileName = Recycler.GetDetailsOf(FI, 0);
    if (Path.GetExtension(FileName) == "") FileName += Path.GetExtension(FI.Path);
    string FilePath = Recycler.GetDetailsOf(FI, 1);
    Console.WriteLine(FilePath);
}

提前谢谢!

推荐答案

我的服务器在回收站中停滞了超过590,000个文件.任何尝试打开回收站的尝试都会导致服务器内存不足并崩溃.

I had a server bogged down with over 590,000 files in the Recycle Bin. Any attempt to open the recycle bin caused the server to run out of memory and crash.

此代码在Powershell ISE中有效.花了将近30分钟.没有错误.

This code worked from Powershell ISE. It took almost 30 minutes. No errors.

Get-ChildItem -Path 'C:\$Recycle.Bin' -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue

这篇关于如何获得回收站的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆