Check if directory exists on Android sdcard with bash

I would like to check whether a directory exists on the sdcard of an Android device using bash. I am aware that a similar question was answered here: Check if a directory exists in a shell script The difference is that when I do

if [ -e /sdcard/myDir ]; then
     # magic
fi

it is checked whether /sdcard/myDir exists on my computer and not on the phone. How can I check if the folder exists on the phone?

Thanks in advance!


If I understood you correctly try:

adb shell

... and then type your shell commands on the device. I'm not really sure if bash is available on standard Android device. I'd bet that there are only simple busybox tools installed.

Also note, that there is very limited set of directories that you will be able to access this way on non-rooted device.

UPDATE: More precisely, if you need to execute some kind of shell script on the remote device, first prepare the script, say foo.sh and then execute:

adb push foo.sh /sdcard/
adb shell sh /sdcard/foo.sh

That should do the trick.


你可以做到以下几点:

if [ `adb shell "if [ -e /sdcard/myDir ]; then echo 1; fi"` ]; then 
   echo "Folder exists";
else
   echo "Folder does not exist";
fi
链接地址: http://www.djcxy.com/p/17494.html

上一篇: Bash脚本目录检测和创建

下一篇: 用bash检查Android sdcard上的目录是否存在