Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Vista Recycle bin work?

I am trying to write a python module to move files to the 'Recycle Bin' on both Mac and PC.

Is there a way, only from the commandline (and yes, I mean using absloutly no C#/C++/etc) to move a file into the Recycle Bin, and have it appear as a file trashed by drag and drop (or deleted via SHFileOperation, etc).

like image 968
FarMcKon Avatar asked Mar 05 '09 01:03

FarMcKon


People also ask

How does the Recycle Bin work?

The Recycle Bin is an analogy to a physical trash can; users place items to be thrown out there, and when the trash can fills up it is emptied. The Recycle Bin is similar as items that are deleted are sent there, then the Recycle Bin may be manually emptied or once it is full, it will remove the oldest files first.

How do I open the Recycle Bin in Vista?

To fix this issue in Windows Vista, follow these steps: Click Start, and then click Control Panel. Click Appearance and Personalization, click Personalization, and then click Change desktop icons. Click to select the Recycle Bin check box, and then click OK.

Does Recycle Bin delete everything?

Isn't deleting files from the Recycle Bin enough to permanently delete data? The direct answer is no. You can treat the Recycle Bin as the last frontier for the data you wish to delete.

Does recycling bin delete files automatically?

Windows 10's Storage Sense feature automatically runs when you're low on disk space. It automatically deletes files more than 30 days old in your Recycle Bin, too. This was on by default on a PC running the May 2019 Update.


3 Answers

Moving files to Windows' Recycle Bin is a Shell operation. Shell operations are run via COM. For older Windows versions there is the SHFileOperation interface. Since Vista there is the new IFileOperation interface.

like image 97
gix Avatar answered Oct 14 '22 03:10

gix


You should use the SHFileOperation function or, on Vista, the IFileOperation interface (as pointed out by gix below).

From the remarks on SHFileOperation:

When used to delete a file, SHFileOperation permanently deletes the file unless you set the FOF_ALLOWUNDO flag in the fFlags member of the SHFILEOPSTRUCT structure pointed to by lpFileOp. Setting that flag sends the file to the Recycle Bin. If you want to simply delete a file and guarantee that it is not placed in the Recycle Bin, use DeleteFile.

like image 35
Joey Avatar answered Oct 14 '22 04:10

Joey


I have written a Python library that does precisely that. You might want to check it out.

like image 22
Virgil Dupras Avatar answered Oct 14 '22 04:10

Virgil Dupras