Move files/directories to Recycle Bin using standard Python libs

kyosohma at gmail.com kyosohma at gmail.com
Wed Aug 15 21:56:48 CEST 2007


On Aug 15, 2:02 pm, "Chris Mellon" <arka... at gmail.com> wrote:
> On 8/15/07, Kevin D.Smith <Kevin.Sm... at sas.com> wrote:
>
> > 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?
>
> > --
> > 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.

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




More information about the Python-list mailing list