-
-
Save berezovskyi/6a3f2f8cd025e301a5eacd807b3893e9 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment