我需要能够测试并查看某个目录是否存在于 Android 设备的 SD 卡上,然后将一些文件推送到该目录(如果存在)。
到目前为止,我有这个:
adb %argument% shell if [ -e /sdcard/ ]; then echo "it does exist"; else echo "it does not exist"; fi;
但是我怎样才能让我的批处理脚本知道该目录存在,以便它可以继续将文件推送到该目录?
最佳答案
这是我在批处理脚本中所做的:
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
)
可能有多个文件符合文件名,所以我选择让它测试大于 0。
要在 Linux 中测试精确匹配和使用 bash (reference):
FILENAME_RESULT=$(adb shell ls / | tr -d '\015'|grep '^fileName$')
if [ -z "$FILENAME_RESULT" ];
then
echo "No fileName found."
else
echo "fileName found."
fi
关于android - 使用 ADB 检查目录是否存在,如果存在则推送文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10901103/