Question

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?

Was it helpful?

OTHER TIPS

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

Hopefully that may be helpful. Works for me )

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top