How does Vista Recycle bin work?
Asked Answered
S

4

5

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).

Seamanship answered 5/3, 2009 at 1:12 Comment(0)
F
5

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.

Foetation answered 5/3, 2009 at 1:17 Comment(2)
Why are you describing a Win32/COM method of doing this, when the question asks for a Python way, explicitly excluding C#, C++, etc?Sielen
There surely must be a way of executing system calls from Python. If not, then it's a broken tool to begin with.Foetation
T
5

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.

Thruway answered 5/3, 2009 at 1:20 Comment(0)
Z
3

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

Zyrian answered 14/6, 2010 at 18:28 Comment(0)
S
-1

It looks like this mailing list entry might help you.

Stupa answered 5/3, 2009 at 1:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.