如何在 Python 中从 Windows 7 遍历连接的 iPhone 上的照片?

Dav*_*vid 5 python windows iphone winapi

当我将我的 iPhone 连接到我的 Windows 7 系统时,Windows 资源管理器打开一个虚拟文件夹到 DCIM 内容。我可以通过 Pywin32 (218) 访问 shell 库接口,如下所述:Can I use library abstractions in python?

给定一个在 Windows 资源管理器中工作的面向用户的编辑路径 (SIGDN_DESKTOPABSOLUTEEDITING),并启动 Windows 照片查看器:

电脑\我的 iPhone\内部存储\DCIM\828RTETC\IMG_2343.JPG

如何获取解析路径 (SIGDN_DESKTOPABSOLUTEPARSING) 以与 SHCreateItemFromParsingName() 一起使用以创建 ShellItem?(从中我将绑定一个流并复制到本地磁盘,如下所示:Can images are read from an iPhone programmatically 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)
Run Code Online (Sandbox Code Playgroud)

最终目标是通过 IShellFolder 接口之类的东西迭代 DCIM“文件夹”,并将最近的照片复制到本地磁盘。我不想为解析名称打开 FileOpenDialog。但在此之前,我认为为其中一个文件创建一个 ShellItem 将是一个很好的测试。

Dav*_*vid 5

我认为@jonathan-potter 的建议是更好的方法,而不是从编辑名称转换为解析名称。这是一个硬编码的片段,显示了如何从桌面文件夹开始并排除错误处理:

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...
Run Code Online (Sandbox Code Playgroud)