How do I adb pull ALL files of a folder present in SD Card

riteshtch picture riteshtch · Apr 7, 2012 · Viewed 189.6k times · Source

I have a folder in my SD Card as: /mnt/sdcard/Folder1/Folder2/Folder3/*.jpg

The name of Folder1 and Folder2 remains constant and inside Folder2 I have Folder3, 4, 5 and so on.. I want to pull all the jpeg files rather than all files (there are more) using adb to my current directory on the computer..

Every folder has different number of jpeg files and other files and I tried using this:

adb pull mnt/sdcard/Folder1/Folder2/Folder/*.jpg .

But it didn't work.. So uhmm how do I adb pull all files present in any folder of SD Card with a single command (single command because each folder has different number of files)

Answer

Jared Burrows picture Jared Burrows · Apr 8, 2012

Single File/Folder using pull:

adb pull "/sdcard/Folder1"

Output:

adb pull "/sdcard/Folder1"
pull: building file list...
pull: /sdcard/Folder1/image1.jpg -> ./image1.jpg
pull: /sdcard/Folder1/image2.jpg -> ./image2.jpg
pull: /sdcard/Folder1/image3.jpg -> ./image3.jpg
3 files pulled. 0 files skipped.

Specific Files/Folders using find from BusyBox:

adb shell find "/sdcard/Folder1" -iname "*.jpg" | tr -d '\015' | while read line; do adb pull "$line"; done;

Here is an explanation:

adb shell find "/sdcard/Folder1" - use the find command, use the top folder
-iname "*.jpg"                   - filter the output to only *.jpg files
|                                - passes data(output) from one command to another
tr -d '\015'                     - explained here: http://stackoverflow.com/questions/9664086/bash-is-removing-commands-in-while
while read line;                 - while loop to read input of previous commands
do adb pull "$line"; done;         - pull the files into the current running directory, finish. The quotation marks around $line are required to work with filenames containing spaces.

The scripts will start in the top folder and recursively go down and find all the "*.jpg" files and pull them from your phone to the current directory.