How can I access my iPhone files (via USB) in Python?

Viewed 2595

I have an iPhone connected to my PC via the lightning to USB cable. It appears as a device under "This PC", and I can copy files from it. I want to automate this using Python, but trying to access "This PC" as a path doesn't work.

import os

path = r"This PC\Apple iPhone\Internal Storage"
for entry in os.listdir(path):
    print(entry)
Traceback (most recent call last):
  File "C:\test.py", line 4, in <module>
    for entry in os.listdir(path):
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'This PC\\Apple iPhone\\Internal Storage'

Some say that the F:\ drive is the one that holds the device files, but the iPhone doesn't register itself as a drive.

How do I find the absolute path of an iPhone and access its files? I'd like suggestions to be available in Python, but any will do.

1 Answers

I don't really get the problem, I am afraid, but as far as I can see, you just want to access a drive that is not C:. You have to find out which drive it is, e.g.F:. Afterwards you can access files like your “local” ones.

f = open(r"F:\iPhonePictures\CuteCats\foo.txt")

The r prefix lets you allow to use escape characters in a string if that was your problem: LTS

Related