简体   繁体   English

如何使用 Windows 上的 Powershell 将多个文件推入/拉出 Android 和 ADB?

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

I need to specifically use Windows 10 Powershell, not gitbash or cygwin or CMD, as other answers on SO have provided.我需要专门使用 Windows 10 Powershell,而不是 gitbash 或 cygwin 或 CMD,因为 SO 上的其他答案已提供。 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).我需要能够使用通配符从 Windows 到 Android 推送到特定文件夹(不是整个文件夹,因为 SO 上的其他答案已经提供)。

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.抱歉,如果这个问题已经得到解答,我还没有找到这个具体的答案。

You can leverage loops in powershell to call adb command separately for each file.您可以利用 powershell 中的循环为每个文件分别调用 adb 命令。 Get the files you want to push or pull, loop through and call adb for each.获取您想要推送或拉取的文件,循环并为每个文件调用 adb。

$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
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM