How to programatically restore a recycle bin item

119 views Asked by At

I would like to restore a deleted file from the Windows recycle bin. I have access to the original file path before deletion and the path of the recycle bin entry. How can I restore the deleted file programmatically using the Windows C++ API? Bonus points if I can restore it to a different path as well.

// The path of the file before it was deleted
wchar_t const *original_path = L"C:\\code\\swan\\ignore\\dir_2\\file1";

// The path of the generated recycle bin entry upon deletion
wchar_t const *recycle_bin_path = L"C:\\$Recycle.Bin\\S-1-5-21-738277947-893724712-3765747123-1001\\$RJB4I8F";

// TODO: restore `recycle_bin_path` to `original_path`
1

There are 1 answers

0
Jeaninez - MSFT On

According to Raymond Chen's recommendations:

You could written a function called WantToRestoreThisItem which studies the properties of a Recycle Bin item and determines whether you want to restore it.

For more details you could refer to the Blog: Invoking commands on items in the Recycle Bin