Python Forum

Full Version: Importing photos from smartphone
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I want my script to import photos from my smartphone, to the raspberry pi.
My code looks like this:
import glob, shutil

source = "mtp://[usb:001,025]/Phone/Pictures/Ballons" and "mtp://[usb:001,025]/Phone/Pictures/Familie" and "mtp://[usb:001,025]/Phone/Pictures/Florida" and "mtp://[usb:001,025]/Phone/Pictures/Ramona" and "mtp://[usb:001,025]/Phone/Pictures/Screenshots"
dest = "/home/pi/Desktop/Photos"

for file in glob.glob(source + "/*.jpg"):
    shutil.copy(file, dest)
I don't see any problem in it, but when I run it nothing happens.
Does anyone have an idea what I did wrong?
See this answer. anding strings, you end up with source having the last value in your expression.
You have to place your URLs into a list and iterate over all locations - or just use os.walk()

for loc, _, files in os.walk('mtp://[usb:001,025]/Phone/Pictures'):
     for file_name in files:
          if file_name.endswith('jpg'):
               shutil.copy(os.path.join(loc, file_name), dest)
(Apr-23-2017, 07:34 PM)volcano63 Wrote: [ -> ]See this answer. anding strings, you end up with source having the last value in your expression.

Evidence:

>>> files = "left" and "middle" and "right"
>>> files
'right'