Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用ADB检查目录是否存在,如果存在,则推送文件_Android_Batch File_Adb - Fatal编程技术网

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

Android 使用ADB检查目录是否存在,如果存在,则推送文件,android,batch-file,adb,Android,Batch File,Adb,我需要能够测试并查看Android设备的SD卡上是否存在一个目录,然后将一些文件推送到该目录(如果确实存在) 到目前为止,我有: adb %argument% shell if [ -e /sdcard/ ]; then echo "it does exist"; else echo "it does not exist"; fi; 但是我如何让我的批处理脚本知道目录存在,以便它可以继续将文件推送到该目录?我认为您应该列出目录dir或ls,然后使用grep进行分析。如果grep找到目录脚本,请

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

到目前为止,我有:

adb %argument% shell if [ -e /sdcard/ ]; then echo "it does exist"; else echo "it does not exist"; fi;

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

我认为您应该列出目录
dir或ls
,然后使用grep进行分析。如果grep找到目录脚本,请执行一些操作。

以下是我在批处理脚本中执行的操作:

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,请执行以下操作:

1) 只需使用adb shell ls/filepath>fileifpresent

2) 本地grep如果“没有这样的文件或目录”,则不存在

 Else Directory Present

下面是如何检查命令的退出状态

MyFile="Random.txt"
WorkingPath="/data/local/tmp/RandomFolder"

IsDir=`adb shell ls $WorkingPath &> /dev/null ; echo "$?"`

if [ $IsDir == 0 ] ; then 

   echo "Exist! Copying File To Remote Folder"

   adb push $MyFile $WorkingPath

else

   echo "Folder Don't Exist! Creating Folder To Start Copying File"

   adb shell mkdir $WorkingPath

   adb push $MyFile $WorkingPath

fi

windows计算机上没有grep。我已经知道了
find
,但是我应该如何使用find设置一些标志,告诉我的下一个命令
将文件推送到设备上呢?我想出来了。感谢您的帮助,并为我指出了更好的解决方案。第一个解决方案应该运行在哪里?窗户?
MyFile="Random.txt"
WorkingPath="/data/local/tmp/RandomFolder"

IsDir=`adb shell ls $WorkingPath &> /dev/null ; echo "$?"`

if [ $IsDir == 0 ] ; then 

   echo "Exist! Copying File To Remote Folder"

   adb push $MyFile $WorkingPath

else

   echo "Folder Don't Exist! Creating Folder To Start Copying File"

   adb shell mkdir $WorkingPath

   adb push $MyFile $WorkingPath

fi