批处理脚本 - 如果存在 ./sdcard/file.any 使用 adb [英] batch scripting - if exist ./sdcard/file.any using adb

查看:28
本文介绍了批处理脚本 - 如果存在 ./sdcard/file.any 使用 adb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查我的 Android 设备上是否存在文件,如果不存在 - 推送它.在批处理中使用 adb 这样做的语法是什么?类似的东西:

I'd like to check whether a file exists on my Android device, and if not - to push it. What is the syntax for doing so using adb on batch? Something like:

if exist ./sdcard/file.any do echo "exists"
else adb push file.any ./sdcard/

推荐答案

Running in a command prompt window if/? or help if 输出内部命令的帮助页面if.

Running in a command prompt window if /? or help if outputs the help pages for internal command if.

命令处理器对语法的容忍度不是很高.else 分支只能使用括号.真正的分支必须有 (,它必须与命令 if 位于同一行,并用空格与条件的最后一个参数分开.

The command processor is not very tolerant on syntax. An else branch is only possible with using parentheses. The true branch must have ( which must be on same line as command if separated with a space from last argument of the condition.

真正分支的结束 ) 可以与开始 ( 或在不同的行上.

The closing ) for true branch can be on same line as opening ( or on a different line.

关键字else必须与空格后真正分支的关闭)在同一行.

The keyword else must be on same line as closing ) of the true branch after a space.

如果 else 分支也使用圆括号,则开头的 ( 必须与 else 在同一行,并用空格分隔关键字.

If round brackets are used also for the else branch, opening ( must be on same line as else separated with a space from the keyword.

关键字do在这里完全错误,因为它是命令FOR的关键字.

The keyword do is completely wrong here as it is a keyword for command FOR.

一些工作变体.

  1. 一行中的所有内容,尽可能少的空格(难以阅读):

  1. Everything on one line with as less spaces as possible (hard to read):

 if exist "directoryfile" (echo exists) else (adb push "file" "directory")

  • 所有内容都在一行上,并有更多空格以便于阅读:

  • Everything on one line with more spaces for easier reading:

     if exist "directoryfile" ( echo exists ) else ( adb push "file" "directory" )
    

  • 第一行条件,第二行真分支,第三行不带括号的分支:

  • Condition on first line, true branch on second line, else branch without parentheses on third line:

     if exist "directoryfile" (
         echo exists
     ) else adb push "file" "directory"
    

  • 整个条件的每一部分在单独的行上:

  • Each part of the entire condition on separate lines:

     if exist "directoryfile" (
         echo exists
     ) else (
         adb push "file" "directory"
     )
    

  • 可能有更多变体,但它们都读起来很糟糕.

    There are more variants possible, but they are all horrible to read.

    最好使用第二个或第四个变体,因为这两个最适合阅读.

    It is best to use second or fourth variant as those two are the best for reading.

    如果也使用 else 分支,我建议始终使用第四个变体.

    I recommend to use always fourth variant if an else branch is used, too.

    .可以省略.

    Windows 上的目录分隔符是反斜杠字符.

    And the directory separator on Windows is the backslash character.

    注意:我不知道 if exists ./sdcard/file.any.sdcardfile.any 是否有效根本.该问题不包含任何关于

    NOTE: I don't know if if exist ./sdcard/file.any or .sdcardfile.any works at all. The question does not contain any information about

    • 安卓版,
    • Android 设备本身,
    • 如何配置设备以访问其存储介质上的文件和目录——作为可移动存储,可以从 Windows 命令行环境或仅通过 Windows 命令行环境不支持的媒体传输协议
    • 这个批处理文件运行在哪个环境中,即当前目录是什么,环境变量PATHPATHEXT的值是多少等
    • Android version,
    • the Android device itself,
    • how the device is configured regarding to accessing files and directories on its storage medias – as removable storage(s) making it possible to access the files and directories from Windows command line environment or just via Media Transfer Protocol which is not supported from Windows command line environment,
    • in which environment this batch file is running, i.e. what is the current directory, what are the values of the environment variables PATH and PATHEXT, etc.

    因此答案仅涵盖 IF 语法错误,而不是如何检查任何 Android 设备上的文件是否存在,任何 Android 版本都连接了任何设备驱动程序和数据存储访问协议用于访问设备.

    So the answer covers only the IF syntax mistake, not how to check for existence of a file on any Android device with any Android version connected with whatever device drivers and data storage accessing protocols are used for accessing the device.

    这篇关于批处理脚本 - 如果存在 ./sdcard/file.any 使用 adb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆