Check if the directory exists using ADB and click the file if it is

I need to check and see if a directory exists on the SD card of an Android device, and then insert several files into this directory if it exists.

So far I have this:

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

But how can I let my script group know that the directory exists so that it can continue to push the file into this directory?

+4
source share
4 answers

Here is what I did in the batch script:

 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 ) 

There may be several files that match the file name, so I decided to check for it greater than 0.


To check the exact match and use bash on Linux ( link ):

 FILENAME_RESULT=$(adb shell ls / | tr -d '\015'|grep '^fileName$') if [ -z "$FILENAME_RESULT" ]; then echo "No fileName found." else echo "fileName found." fi 
+3
source

I think you should list the dir or ls directory and then parse with grep. If grep found the script directory to do something.

+1
source

1) Just use adb shell ls / filepath> fileifpresent

2) grep locally, if "There is no such file or directory", then NO

  Else Directory Present 
0
source

Here's how I do it by checking the exit status of the team

 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 
0
source

Source: https://habr.com/ru/post/1416183/


All Articles