Skip to content

Instantly share code, notes, and snippets.

@TJYSunset
Last active February 12, 2022 15:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TJYSunset/78379441aceb33e87a9944432292cad9 to your computer and use it in GitHub Desktop.
Save TJYSunset/78379441aceb33e87a9944432292cad9 to your computer and use it in GitHub Desktop.
This program restores all files in your recycle bin. I wrote this because explorer failed to restore too many files. It's tested on Windows 10, Chinese Simplified and must be edited to run properly on Windows of other languages.
using System;
using System.Runtime.InteropServices;
using Shell32;
namespace UnrecycleThem
{
public class UnrecycleThem
{
public static void Main(string[] args)
{
var recycler = NameSpace(10); // Magic number
var items = recycler.Items();
var total = items.Count;
var count = 0;
Console.WriteLine($"Recycle Bin Items count: {total}");
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
for (var i = 0; i < items.Count; i++)
{
var fi = items.Item(i);
DoVerb(fi, @"还原(&E)"); // Replace this with the command shown in your explorer
count++;
Console.CursorLeft = 0;
Console.Write($"{count + 1}/{total}");
Console.Write(" "); // clear line
}
Console.WriteLine();
Console.WriteLine("Done!");
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
}
private static Folder NameSpace(object path) // Necessary for Windows 10
{
var shellAppType = Type.GetTypeFromProgID("Shell.Application");
var shell = Activator.CreateInstance(shellAppType);
var val = (Folder) shellAppType.InvokeMember("NameSpace",
System.Reflection.BindingFlags.InvokeMethod, null, shell, new[] {path});
Marshal.ReleaseComObject(shell);
return val;
}
private static void DoVerb(FolderItem item, string verb)
{
foreach (FolderItemVerb fiVerb in item.Verbs())
{
if (fiVerb.Name != verb) return;
fiVerb.DoIt();
}
}
}
}
@Shazzababa
Copy link

Hi!

I have the same problem as the person you replied to here (https://superuser.com/questions/1183215/how-to-restore-large-amount-of-file-from-recycle-bin).

I however, despite being very tech-literate, have zero idea how to code or use code. Could you point me in the direction of where I might read up on the above to apply it to my recycle bin issue? As I'm implying, I'm happy to do the grunt work myself of applying it, I just haven't a clue even where to begin googling how to approach the problem of appyling said code.

Hope you can help!

Shaun

@TJYSunset
Copy link
Author

@Shazzababa

  1. download Visual Studio Community 2019 and choose .NET Desktop development during installation
  2. create a console application like this
  3. paste the code above but modify line 21 to match your Windows language
  4. add a reference to Shell32
  5. run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment