如何在Windows 7中用Python遍历连接的iPhone上的照片? [英] How can I iterate across the photos on my connected iPhone from Windows 7 in Python?
问题描述
当我将iPhone连接到Windows 7系统时,Windows资源管理器将打开一个虚拟文件夹以显示DCIM内容.我可以通过Pywin32(218)访问外壳程序库界面,如此处所述:在python中使用库抽象?
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?
给出在Windows资源管理器中可用的面向用户的编辑路径(SIGDN_DESKTOPABSOLUTEEDITING),然后启动Windows Photo Viewer:
Given a user-facing editing path (SIGDN_DESKTOPABSOLUTEEDITING) that works in the Windows Explorer, and launches the Windows Photo Viewer:
计算机\我的iPhone \内部存储\ DCIM \ 828RTETC \ IMG_2343.JPG
Computer\My iPhone\Internal Storage\DCIM\828RTETC\IMG_2343.JPG
如何获取与SHCreateItemFromParsingName()一起使用以创建ShellItem的解析路径(SIGDN_DESKTOPABSOLUTEPARSING)? (我将从中将流绑定并复制到本地磁盘,如下所示:
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)
最终目标是通过IShellFolder接口之类的方法迭代DCIM文件夹",并将最新照片复制到本地磁盘.我不想为解析名称打开FileOpenDialog.但是在此之前,我认为为其中一个文件创建ShellItem是一个很好的测试.
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.
推荐答案
我认为@ jonathan-potter的建议不是从编辑名称转换为解析名称的替代方法.这是一个硬编码的片段,显示了如何从Desktop文件夹开始,并且排除了错误处理:
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...
这篇关于如何在Windows 7中用Python遍历连接的iPhone上的照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!