Last active
February 12, 2022 15:23
-
-
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.
This file contains 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(); | |
} | |
} | |
} | |
} |
- download Visual Studio Community 2019 and choose .NET Desktop development during installation
- create a console application like this
- paste the code above but modify line 21 to match your Windows language
- add a reference to Shell32
- run
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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