Delete one item from the recycle bin

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

While searching the Internet, I only found ways to delete to the trash, not FROM. I also do not want to clear the entire container, only one specific file. A specific item is already in the basket.

How can i do this?

EDIT:

  • I did not put the file there myself, nor my program. Someone else did it, I do not control it.
  • Windows search can somehow find my file ...?!?

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

+3
source share
4 answers

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

0
source
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)
    {
        ...
    }

, . )

0

, , ? , , , .

-1

Source: https://habr.com/ru/post/1712463/


All Articles