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:
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With