如何使用ADB在Android上删除文件

时间:2019-01-21 05:06:43

标签: android adb

我正在尝试使用一个ADB命令删除我Android上的文件。

我了解您可以执行adb shell,然后使用rm删除文件。

但是我需要将其作为一行执行。

我尝试过:

adb rm-f /directory/file.txt

adb shell rm-f /directory/file.txt

不要删除我想要的文件。

2 个答案:

答案 0 :(得分:2)

我在您的评论中注意到,您将要使用一行代码,因为您将要使用Python。另外,您也可以使用subprocess module写入stdout,从而使您可以执行许多选择的命令

例如

import subprocess

process = subprocess.Popen([r'adb', 'arg1', 'arg2'], stdout=subprocess.PIPE,stdin=
subprocess.PIPE) #start adb
process.stdin.write('shell \n') # Parse in input into the program
process.stdin.write('rm *\n') # Parse in second input
line=process.stdout.readline() # Read a line from stdout

答案 1 :(得分:0)

在安卓上删除文件:

adb shell rm sdcard/download/file.ext