Search code examples
batch-filecommandadb

Batch file help 2 commands for adb at once


Im tryin to set 2 commands for a folder of apks im trying to push to /system/app/

so what im trying to do is push all apks in a folder to /system/app/ then set a chmod 644 command for those files being pushed

what i have is this to push the apks

for /f %%a IN ('dir /b SystemAPKs\*.apk') do stuff\adb.exe push SystemAPKs\%%a  /system/app/

what would be the best way to do this? Thanks


Solution

  • Perform multiple operations in the for loop. Something like this:

    for /f %%A IN ('dir /b SystemAPKs\*.apk') do (
        stuff\adb.exe push "%%~fA" /system/app/
        stuff\adb.exe shell chmod 644 "/system/app/%%~nxA"
    )
    

    Update, lets change the working directory of the script. This will allow us to invoke adb with just the file name instead of the entire file path.

    • Root
      • Script.bat
      • SystemAPKs
        • apk files to push
      • stuff
        • adb.exe
      • MarketAPKs
      • Nexus 4 drivers

    Directory Structure

    :: Make SystemAPKs the Working Directory
    pushd SystemAPKs
    for /f %%A IN ('dir /b *.apk') do (
        ..\stuff\adb.exe push "%%~nxA" /system/app/
        ..\stuff\adb.exe shell chmod 644 "/system/app/%%~nxA"
    )
    popd