从回收站删除单个项目

发布于 2024-07-27 22:14:34 字数 369 浏览 10 评论 0原文

C# 中是否有任何方法(可能是互操作)可以永久删除回收站中的特定文件?

在互联网上搜索时,我只找到了删除“到”回收站的方法,而不是“从”删除的方法。 我也不想清空整个垃圾箱,只想清空一个特定文件。 该特定项目已在回收站中。

我怎样才能做到这一点?

编辑:

  1. 我自己没有把文件放在那里,我的程序也没有放在那里。 别人这么做了,所以我无法控制。
  2. Windows 搜索以某种方式能够找到我的文件...?!?

我发现了另一件事,我实际上可以在 C:\RECYCLER 中找到一个具有相同文件扩展名但名称不同的文件。 那么我如何判断这是否真的是我正在寻找的文件呢?

Is there any way in C# (interop maybe) to delete a specific file in the recycle bin permanently?

While searching on the internet I only found ways to delete TO the recycle bin not FROM.
I also don't want to empty the whole bin, just one specific file. The specific item is already in the recycle bin.

How can I do this?

EDIT:

  1. I didn't put the file there myself, nor my program. Somebody else did so I have no control over that.
  2. Windows Search somehow is able to find my file...?!?

I found out another thing, I can actually find a file in C:\RECYCLER with the same file extension but a different name. So how can I tell if that is really the file I'm looking for?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

2024-08-03 22:14:34

您需要参考:

using Shell32;

代码:

var shl = new Shell();

// Get recycle folder
Folder recycler = shl.NameSpace(10);

FolderItems items = recycler.Items();
for (int i = 0; i < items.Count; i++)
{
    try
    {
        FolderItem fi = items.Item(i);
        string fileName = recycler.GetDetailsOf(fi, 0);
        string filePath = recycler.GetDetailsOf(fi, 1);
        string recyleDate = recycler.GetDetailsOf(fi, 2);
        
        if (fileName == "your file/folder")
        {
            // check if chosen item is a folder
            if (fi.IsFolder)
            {
                Directory.Delete(fi.Path, true);
            }
            else
            {
                File.Delete(fi.Path);
            }
        }
    }
    catch (Exception exc)
    {
        ...
    }
}

希望这可能有所帮助。 对我有用。

You need to reference:

using Shell32;

Code:

var shl = new Shell();

// Get recycle folder
Folder recycler = shl.NameSpace(10);

FolderItems items = recycler.Items();
for (int i = 0; i < items.Count; i++)
{
    try
    {
        FolderItem fi = items.Item(i);
        string fileName = recycler.GetDetailsOf(fi, 0);
        string filePath = recycler.GetDetailsOf(fi, 1);
        string recyleDate = recycler.GetDetailsOf(fi, 2);
        
        if (fileName == "your file/folder")
        {
            // check if chosen item is a folder
            if (fi.IsFolder)
            {
                Directory.Delete(fi.Path, true);
            }
            else
            {
                File.Delete(fi.Path);
            }
        }
    }
    catch (Exception exc)
    {
        ...
    }
}

Hopefully that may be helpful. Works for me.

空心↖ 2024-08-03 22:14:34

我从未尝试过,但您可以在每个单元都有的隐藏文件夹“RECYCLER”中搜索要删除的项目,并将其删除。

I never tried it but you can search for the item you want to delete in the hidden folder "RECYCLER" that each unit has, and delete it.

蹲在坟头点根烟 2024-08-03 22:14:34

这可能是一个愚蠢的问题,但是该文件是否因为您的程序将其放在那里而进入了回收站? 如果是这样,您可以使用正常的文件操作删除该文件并完全绕过回收站。

This may be a stupid question, but did the file go into the recycle because your program put it there? If so, you can just delete the file using normal file operations and bypass the recycle bin entirely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文