How to push/pull multiple files to/from Android with ADB using Powershell on Windows?

Viewed 50

I need to specifically use Windows 10 Powershell, not gitbash or cygwin or CMD, as other answers on SO have provided. I need to be able to use wildcards. I need to be able to push from Windows to Android to a specific folder using wildcards (not entire folder at a time as other answers on SO have provided).

Ex: adb push *.png /sdcard/Android/data/myapp/files
Ex: adb pull /sdcard/Android/data/myapp/files/h*.txt

Apologies if this has been answered, I have yet to find this specific answer.

1 Answers

You can leverage loops in powershell to call adb command separately for each file. Get the files you want to push or pull, loop through and call adb for each.

$adb = 'C:\temp\platform-tools\adb.exe'
$local = 'C:\temp\testfiles'
$remote = '/sdcard/Android/data/myapp/files'

function push-adbfiles {
    param ()
    # use Get-ChildItem to capture which files to push
    $files = Get-ChildItem -file $local\*.png

    # loop using ForEach-Object and call adb push command for each
    $files | ForEach-Object {
        & $adb push $_ $remote 
    } 
}


function pull-adbfiles {
    param ()
    # use nix find command to find and return full path of matching files
    $files = & $adb shell find "$remote/h*"

    # loop through files running adb pull on each
    $files | ForEach-Object {
        & $adb pull $_ $local
    }
}
Related