python - 如何使用 Python 从 Windows 7 中迭代连接的 iPhone 上的照片?

标签 python iphone windows winapi

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

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

Computer\My iPhone\Internal Storage\DCIM\828RTETC\IMG_2343.JPG

如何获取解析路径 (SIGDN_DESKTOPABSOLUTEPARSING) 以便与 SHCreateItemFromParsingName() 一起使用来创建 ShellItem? (我将从中绑定(bind)一个流并复制到本地磁盘,如下所示: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 接口(interface)等方式迭代 DCIM“文件夹”,并将最新照片复制到本地磁盘。我不想打开 FileOpenDialog 来解析名称。但在达到这一点之前,我认为为其中一个文件创建 ShellItem 将是一个很好的测试。

最佳答案

我认为 @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...

关于python - 如何使用 Python 从 Windows 7 中迭代连接的 iPhone 上的照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27593315/

相关文章:

ruby-on-rails - windows 10 ruby​​2.5 rails 5.1.5 无法加载这样的文件——sqlite3/sqlite3_native (LoadError)

python - 向后切片元组 - 如何处理获取第一个元素?

python - glGenTextures 中的 pyopengl 错误

python - MongoDB 文件路径作为唯一索引

Python - 列表检查某些内容是否已经随机化

iphone - 在不是 ICarousel 中的 subview 的标签中显示 iCarousel 的当前索引

windows - 如何创建一个.bat文件,允许我输入输入(或者更好的是,从剪贴板获取输入)?

iphone - 适用于多个客户端的 iOS Enterprise Distribution

javascript - iPhone 中的调用自动化

windows - 编译后命令提示符更改颜色