【问题标题】:Check if directory exists on Android SD card with Bash使用 Bash 检查 Android SD 卡上是否存在目录
【发布时间】:2011-10-28 00:47:51
【问题描述】:

我想使用 Bash 检查 Android 设备的 SD 卡上是否存在目录。

我知道这里回答了类似的问题:How can I check if a directory exists in a Bash shell script?

不同的是,当我这样做时

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

检查 /sdcard/myDir 是否存在于我的计算机上而不是手机上。如何查看手机上是否存在文件夹?

【问题讨论】:

    标签: android shell


    【解决方案1】:

    您可以执行以下操作:

    if [ `adb shell "if [ -e /sdcard/myDir ]; then echo 1; fi"` ]; then 
       echo "Folder exists";
    else
       echo "Folder does not exist";
    fi
    

    【讨论】:

      【解决方案2】:

      如果我理解正确,请尝试:

      adb shell
      

      ... 然后在设备上键入您的 shell 命令。我不确定 bash 是否可以在标准 Android 设备上使用。我敢打赌,只安装了简单的busybox工具。

      另请注意,您可以在非 root 设备上以这种方式访问​​的目录集非常有限。

      更新: 更准确地说,如果你需要在远程设备上执行某种 shell 脚本,首先准备好脚本,比如foo.sh,然后执行:

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

      这应该可以解决问题。

      【讨论】:

      • 我的 PC 上有一个脚本,用于查询文件夹是否存在。我认为该命令应该类似于if [ adb shell -d $myFolder]; then adb shell rm -r "$myFolder" fi
      • 在这种情况下,创建 foo.sh 文件,其中包含:if [ -d $myfolder]; then adb shell rm -r $myfolder fi 并按说明在设备上推送并运行它。
      猜你喜欢
      • 2011-02-07
      • 1970-01-01
      • 2012-07-02
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 2020-08-09
      • 2012-08-05
      • 2020-06-07
      相关资源
      最近更新 更多