Issue
When I connect my iPhone to my Windows 7 system, the Windows Explorer opens a Virtual Folder to the DCIM content. I can access the shell library interface via Pywin32 (218) as mentioned here: Can I use library abstractions in python?
Given a user-facing editing path (SIGDN_DESKTOPABSOLUTEEDITING) that works in the Windows Explorer, and launches the Windows Photo Viewer:
Computer\My iPhone\Internal Storage\DCIM\828RTETC\IMG_2343.JPG
How can I obtain a parsing path (SIGDN_DESKTOPABSOLUTEPARSING) for use with SHCreateItemFromParsingName() to create a ShellItem? (From which I'd bind a stream and copy to a local disk like this: Can images be read from an iPhone programatically using CreateFile in Windows? )
from win32com.shell import shell
edit_path = r'Computer\My iPhone\Internal Storage\DCIM\828RTETC\IMG_2343.JPG'
parse_path = # How to convert edit_path to a SIGDN_DESKTOPABSOLUTEPARSING path?
i = shell.SHCreateItemFromParsingName(parse_path, None, shell.IID_IShellItem)
The final goal will be to iterate the DCIM "folder" via something like the IShellFolder interface, and copy the most recent photos to the local disk. I don't want to have to open a FileOpenDialog for the parsing name. But before getting to that point, I thought creating a ShellItem for one of the files would be a good test.
Solution
Instead of translating from an editing name to a parsing name, I think @jonathan-potter's suggestion is a better way to go. Here's a hard-coded snippet that shows how to start at the Desktop folder and excludes error handling:
from win32com.shell import shell, shellcon
desktop = shell.SHGetDesktopFolder()
for pidl in desktop:
if desktop.GetDisplayNameOf(pidl, shellcon.SHGDN_NORMAL) == "Computer":
break
folder = desktop.BindToObject(pidl, None, shell.IID_IShellFolder)
for pidl in folder:
if folder.GetDisplayNameOf(pidl, shellcon.SHGDN_NORMAL) == "My iPhone":
break
folder = folder.BindToObject(pidl, None, shell.IID_IShellFolder)
for pidl in folder:
if folder.GetDisplayNameOf(pidl, shellcon.SHGDN_NORMAL) == "Internal Storage":
break
# And so on...
Answered By - David
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.