Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if directory exists using ADB and push a file if it does

I need to be able to test and see if a directory exists on the SD card of an Android device and then push a few files to that directory if it does exist.

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 batch script know that the directory exists so that it can continue to push the file to that directory?

like image 856
prolink007 Avatar asked Jun 05 '12 16:06

prolink007


1 Answers

Here is what I have done in 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 could be multiple files that fit the fileName, so I chose to have it test greater than 0.


To test for exact match and using bash in Linux (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
like image 111
prolink007 Avatar answered Sep 23 '22 14:09

prolink007