使用ADB检查目录是否存在,如果存在则推送文件(Check if directory exists using ADB and push a file if it does)
我需要能够测试并查看Android设备的SD卡上是否存在目录,然后将一些文件推送到该目录(如果存在)。
到目前为止,我有这个:
adb %argument% shell if [ -e /sdcard/ ]; then echo "it does exist"; else echo "it does not exist"; fi;
但是,如何让我的批处理脚本知道该目录是否存在,以便它可以继续将文件推送到该目录?
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?
原文:https://stackoverflow.com/questions/10901103
更新时间:2020-02-24 17:02
最满意答案
这是我在批处理脚本中所做的:
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
)
可能有多个文件适合fileName,所以我选择让它测试大于0。
要测试完全匹配并在Linux中使用bash( 参考 ):
FILENAME_RESULT=$(adb shell ls / | tr -d '\015'|grep '^fileName$')
if [ -z "$FILENAME_RESULT" ];
then
echo "No fileName found."
else
echo "fileName found."
fi
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
2017-05-23
相关问答
正如我在您的问题中所读到的,您非常清楚可以将文件从Android设备提取到PC,因此我不会建议您这样做。 回答你的问题: 不 ,这是不可能的。 这不是adb工作方式。 即使您可以从Android“推送”到PC,您也需要一个软件来处理数据。 Android不包含任何可能的API,也不包含Android SDK的任何部分。 您仍然可以使用您已经知道的任何方法( adb pull ,Eclipse DDMS View,是的,甚至是您自己建议的日志记录Web服务)。 希望这有点澄清。 As I can r
...
从Ubuntu终端,下面为我工作。 ./adb push '/home/webonise/Downloads/one.jpg' '/data/local/'
From Ubuntu Terminal, below works for me. ./adb push '/home/hardik.trivedi/Downloads/one.jpg' '/data/local/'
在Linux上,包含adb Android SDK platform-tools包曾经是32bit 。 它在32bit系统上工作正常。 但是在64bit系统上,您需要手动安装IA32库。 对于基于Debian的发行版,请尝试: sudo apt-get install libc6-i386 lib32stdc++6 lib32gcc1 lib32ncurses5
但由于v24.0 platform-tools仅包含64bit二进制文件,因此不再需要32bit库。 On Linux, Androi
...
首先从批处理开始,将基于IP更新单个Android设备而不会出现问题。 现在看来mount有一些问题。 在此之后添加FOR将从批处理命令行参数中读取IP。 @echo off
for %%a in (%*) do (
echo updating ip %%a
// YOUR BATCH GOES HERE
)
运行如下: update.bat 192.168.4.1 192.168.4.2 192.168.4.3 。 请注意,您的设备将按顺序更新。 或者,您可以将IP放入文本文件
...
我已经用这种方式解决了: public class Utils {
private static final String[] WIN_RUNTIME = { "cmd.exe", "/C" };
private static final String[] OS_LINUX_RUNTIME = { "/bin/bash", "-l", "-c" };
private Utils() {
}
private static T[] concat(T[
...
通常,访问系统文件夹需要root权限,因此除非您拥有root权限,即拥有超级用户权限,否则无法访问系统文件夹或更改其权限。 检查一下: Rooting samsung Nexus S , Okay I have done rooting of my device and push files into it. To root your Android Nexus S device check How to get root and recovery for Nexus S on Windoes 7
...
执行此操作的最佳方法是首先检查文件是否存在以及是否存在然后同步它,如果不存在则再推送。 批处理脚本的骨架来执行此操作: FILENAME_RESULT=$(adb shell ls / | tr -d '\015'|grep '^fileName$')
if [ -z "$FILENAME_RESULT" ];
then
REM adb push because the file was not found
else
REM adb sync because the file wa
...
adb的local_build_list()利用主机c库readdir()函数。 请参阅https://android.googlesource.com/platform/system/core/+/froyo-release/adb/file_sync_client.c man 3 readdir似乎没有说明将返回目录条目的顺序,它可能很大程度上取决于主机文件系统的内部。 adb's local_build_list() utilizes the host c library readdir()
...
尝试 adb push "~/Music/iTunes/iTunes Media/Music/${SONG}" "/storage/self/primary/Music/${SONG}"
而不是你自己的路线 try adb push "~/Music/iTunes/iTunes Media/Music/${SONG}" "/storage/self/primary/Music/${SONG}"
instead of your own line
这是我在批处理脚本中所做的: 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
)
可能有多个文件适合fileName,所以我选择让它测试大于0。 要测试完全匹配并在Linux中使用bash( 参考 ): F
...