1

In the code I maintain I run across:

from win32com.shell import shell, shellcon
# ...
result,nAborted,mapping = shell.SHFileOperation(
        (parent,operation,source,target,flags,None,None))

In Python27\Lib\site-packages\win32comext\shell\ (note win32comext) I just have a shell.pyd binary.

  1. What is the return value of shell.SHFileOperation for a deletion (operation=FO_DELETE in the call above) ? Where is the code for the shell.pyd ?
  2. Can I get the list of files actually deleted from this return value or do I have to manually check afterwards ?

EDIT: accepted answer answers Q1 - having a look at the source of pywin32-219\com\win32comext\shell\src\shell.cpp I see that static PyObject *PySHFileOperation() delegates to SHFileOperation which does not seem to return any info on which files failed to be deleted - so I guess answer to Q2 is "no".

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361

1 Answers1

1

ActiveState Python help contains SHFileOperation description:

shell.SHFileOperation

int, int = SHFileOperation(operation)

Copies, moves, renames, or deletes a file system object.


Parameters

operation : SHFILEOPSTRUCT

Defines the operation to perform.


Return Value

The result is a tuple containing int result of the function itself, and the result of the fAnyOperationsAborted member after the operation. If Flags contains FOF_WANTMAPPINGHANDLE, returned tuple will have a 3rd member containing a sequence of 2-tuples with the old and new file names of renamed files. This will only have any content if FOF_RENAMEONCOLLISION was specified, and some filename conflicts actually occurred.

Source code can be downloaded here: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/ (pywin32-219.zip)

Just unpack and go to .\pywin32-219\com\win32comext\shell\src\

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • Thanks - could you add a link to active python ? Plus those `FOF_WANTMAPPINGHANDLE` maps are valid when moving files - I am interested in delete - I want to avoid a `for fil in toDelete: if file.exists(): updateSomeUI(fil)` loop after I call the `shell.SHFileOperation(FO_DELETE)` (which may raise (?)) – Mr_and_Mrs_D Mar 16 '15 at 20:58
  • For those who like me don't know wahtr AS Python is: http://stackoverflow.com/a/1352541/281545 – Mr_and_Mrs_D Mar 16 '15 at 21:03
  • Did you try `shutil.rmtree(...)`? It has `onerror` parameter to set handler if not deleted. – Vasily Ryabov Mar 17 '15 at 09:13
  • source is a file or a list of files (not a tree) + those who wrote this want apparently the windows native dialogs - accepting though cause the link to the source partially answers Q2 too :) – Mr_and_Mrs_D Mar 17 '15 at 22:28