Using ADB To Deploy Music to An Android Device

I like to manually manage my collection of MP3 files on my Android phone. Making folders and copying contents by hand in Windows Explorer is a pain, since I also have FLAC files that I usually don’t want to copy. Here is a batch file I made that uses ADB to copy all of the album folders in the current directory, along with all contained MP3 and JPG files.

Three assumptions are made:
1) Music files are stored on the SD card.
2) Music files are stored using the folder layout of Music/Artist/Album.
3) This batch file is called from the Artist directory on the PC.

@echo off
REM This script copies deploys music files to the connected Android device.
REM All subfolders are created and all .mp3 and .jpg files are copied.

REM Get the SD card folder under /storage.  It will be in the form of 1234-5678:
set SDCARD_FOLDER=
for /f "usebackq delims==" %%i in (`adb shell "ls -d /storage/????-????"`) do set SDCARD_FOLDER=%%i

if "%SDCARD_FOLDER%" == "" goto NoSDCardFolder

REM Get the name of the current folder without any leading path:
for %%i in (.) do set current_folder=%%~ni%%~xi

REM Make sure this artist folder exists on the Android device:
adb shell "mkdir \"%SDCARD_FOLDER%/Music/%current_folder%\""

REM For each subfolder...
for /f "usebackq delims==" %%i in (`dir /b /ad`) do (
    echo "%%i"

    REM Make this subfolder on the Android device:
    adb shell "mkdir \"%SDCARD_FOLDER%/Music/%current_folder%/%%i\""

    REM Enter the subfolder and copy each file to the Android device...
    pushd "%%i"
    for /f "usebackq delims==" %%j in (`dir /b /a-d *.mp3;*.jpg`) do (
        adb push "%%j" "%SDCARD_FOLDER%/Music/%current_folder%/%%i/%%j"
    )
    popd
)

exit /b

:NoSDCardFolder
echo Unable to find SD card folder on Android device.

About Jeff Fitzsimons

Jeff Fitzsimons is a software engineer in the Pacific Northwest. Technical specialties include C++, Win32, and multithreading. Personal interests include rock climbing, cycling, motorcycles, and photography.
This entry was posted in Technology, Windows. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *