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

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

问题描述

我想检查是否存在的文件,我的Andr​​oid设备上,如果没有 - 推它。什么是这样做的使用上一批亚行语法?
是这样的:

 是否存在./sdcard/file.any做回声存在
亚行还推file.any ./sdcard/


解决方案

在命令提示符窗口中运行如果/?帮助,如果输出用于内部命令帮助页面,如果

命令处理程序是不是语法很宽容。一个其他分支仅适用于使用括号可能。真正的分支必须具有这必须在同一行的命令如果从第二个比较字符串用空格隔开。

闭幕真正的分支可以在同一行开始或在另一条线路。

关键字其他必须在同一行结束空格后的真实分支。

如果还用于else分支圆括号中,打开必须在同一行其他分离与从关键字的空间中。

关键字不要是完全错误的在这里,因为它是命令中的关键字作为

有些工作变种。


  1. 在同一行的一切作为与少的空间尽可能(难以阅读):

     如果存在目录\\文件(回声存在)其他(亚行推文件,目录)


  2. 在同一行的一切为方便阅读更多空间:

     如果存在目录\\文件(回声存在)其他(亚行推文件,目录)


  3. 在第一行,第二行中真正的分支,else分支而对第三行的括号条件:

     如果存在目录\\文件(
        回声存在
    )其他亚行推文件,目录


  4. 在单独行的整个状况的各个部分:

     如果存在目录\\文件(
        回声存在
    )其他(
        亚行推文件,目录


有更多的变种可能的,但他们都是可怕的阅读。

最好是使用第二或第四变种那些2是最好的阅读。

我建议使用始终第四变种如果使用的是其他分支了。

\\ 在文件名开头/可以省略目录名。

和在Windows目录分隔符是反斜杠字符。

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 outputs the help pages for internal command 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 by a space from second compare string.

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

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

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.

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

Some of the working variants.

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

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

  2. Everything on one line with more spaces for easier reading:

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

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

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

  4. Each part of the entire condition on separate lines:

    if exist "directory\file" (
        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 2 are the best for reading.

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

.\ at beginning of file name / directory name could be omitted.

And the directory separator on Windows is the backslash character.

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

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