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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With