Move files/directories to Recycle Bin using standard Python libs

K

Kevin D. Smith

I would like to move files and directories to the Recycle Bin on
Windows from Python. I have found some older articles describing how
to do this, but they require additional packages to be installed. I'm
working on a plugin for an existing project and only have the standard
library to work with. Is there a way to use the Recycle Bin using
standard Python?
 
K

kyosohma

I would like to move files and directories to the Recycle Bin on
Windows from Python. I have found some older articles describing how
to do this, but they require additional packages to be installed. I'm
working on a plugin for an existing project and only have the standard
library to work with. Is there a way to use the Recycle Bin using
standard Python?

Sounds like a Windows only thing to me, so you'll probably have to use
the win32 package regardless. See the following links:

http://mail.python.org/pipermail/python-list/2004-October/287638.html
http://tgolden.sc.sabren.com/python/win32_how_do_i/copy-a-file.html

Mike
 
C

Chris Mellon

I would like to move files and directories to the Recycle Bin on
Windows from Python. I have found some older articles describing how
to do this, but they require additional packages to be installed. I'm
working on a plugin for an existing project and only have the standard
library to work with. Is there a way to use the Recycle Bin using
standard Python?


Not easily. The recycle bin is part of the shell, and the shell api
calls have very complicated struct parameters that are cumbersome to
use correctly from ctypes. If you do the work to map the fileop
structs to ctypes you can call the shell API file operation functions
in shell32.dll. This assumes that "standard" for you is Python 2.5,
which has ctypes. Otherwise you are out of luck.
 
K

Kevin D. Smith

Not easily. The recycle bin is part of the shell, and the shell api
calls have very complicated struct parameters that are cumbersome to
use correctly from ctypes. If you do the work to map the fileop
structs to ctypes you can call the shell API file operation functions
in shell32.dll. This assumes that "standard" for you is Python 2.5,
which has ctypes. Otherwise you are out of luck.

Unfortunately, I need this to work on Python 2.4 as well...
 
K

kyosohma

Not easily. The recycle bin is part of the shell, and the shell api
calls have very complicated struct parameters that are cumbersome to
use correctly from ctypes. If you do the work to map the fileop
structs to ctypes you can call the shell API file operation functions
in shell32.dll. This assumes that "standard" for you is Python 2.5,
which has ctypes. Otherwise you are out of luck.

Technically, you can download ctypes for 2.3/2.4 as well or compile it
for whatever version you want, I think. See here:
http://sourceforge.net/project/showfiles.php?group_id=71702&package_id=71318

Besides, you can bypass ctypes and use SHFileOperation to do it, as is
shown here:
http://tgolden.sc.sabren.com/python/win32_how_do_i/copy-a-file.html

Mike
 
C

Chris Mellon

As I mentioned in my previous post, you can download ctypes from
sourceforge for 2.4.

Mike

If you're going to install a third party lib, install pywin32 and do
it the easy way. OP said he wanted to it with standard library only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top