Skip to content

Instantly share code, notes, and snippets.

@nalf3in
Last active July 2, 2020 16:25
Show Gist options
  • Save nalf3in/7f09072454d80fbb2e833cda8bd0a9d6 to your computer and use it in GitHub Desktop.
Save nalf3in/7f09072454d80fbb2e833cda8bd0a9d6 to your computer and use it in GitHub Desktop.
Script to backup your Android phone photos, requires adb to be in your path
import subprocess
import os
DEVICE = "10.0.0.4:5555"
SEPARATOR = "---------------"
subprocess.run(["adb", "devices"], stdout=subprocess.DEVNULL)
subprocess.run(["adb", "connect", DEVICE], stdout=subprocess.DEVNULL)
subprocess.run(["echo", SEPARATOR], shell=True, stdout=subprocess.DEVNULL)
shell_output = subprocess.run(["adb", "shell", "ls -1 /sdcard/dcim/camera"], capture_output=True, text=True)
filenames = shell_output.stdout.splitlines()
os.makedirs("photos", exist_ok=True)
for name in filenames:
subprocess.run(["adb", "pull", f"/sdcard/dcim/camera/{name}", f"{os. getcwd()}/photos/{name}"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment