使用 ADB 检查目录是否存在,如果存在则推送文件

pro*_*007 5 android batch-file adb

我需要能够测试并查看 Android 设备的 SD 卡上是否存在目录,然后将一些文件推送到该目录(如果确实存在)。

到目前为止,我有这个:

adb %argument% shell if [ -e /sdcard/ ]; then echo "it does exist"; else echo "it does not exist"; fi;
Run Code Online (Sandbox Code Playgroud)

但是如何让我的批处理脚本知道该目录存在,以便它可以继续将文件推送到该目录?

pro*_*007 4

这是我在批处理脚本中所做的事情:

set cmd="adb shell ls | find /c "theFile" "
FOR /F %%K IN (' !cmd! ') DO SET TEST=%%K
if !TEST! GTR 0 (
    echo the file exists
) else (
    echo the file does not exist
)
Run Code Online (Sandbox Code Playgroud)

可能有多个文件符合 fileName,因此我选择让它测试大于 0。


要测试完全匹配并在 Linux 中使用 bash(参考):

FILENAME_RESULT=$(adb shell ls / | tr -d '\015'|grep '^fileName$')

if [ -z "$FILENAME_RESULT" ];
then
        echo "No fileName found."
else
        echo "fileName found."
fi
Run Code Online (Sandbox Code Playgroud)