1. adb命令的执行:os.system()
例如 adb root, adb push, adb pull, 可以用 os.system()来实现,例如os.system("adb push e:\\tmp\\email_eception.log /sdcard/")
2.目录操作: os.chdir(),os.getcwd()
os.chdir('e:\\tmp')
os.getcwd()
3. 创建以时间命名的文件夹 (很实用的一个方法)
首先获取时间:time.ctime(), 获得的时间格式如"Mon Oct 31 15:48:30 2011",因为window不支持文件夹名包括“:”,并且带有空格也会带来兼容性的问题,可以用字符串处理函数str.replace来将空格用“_”替换,将“:”删除,st2.replace(" ","_").replace(":","")
4. 判断文件是否存在
os.path.exists(), 返回True 或 False
os.path.exists("D:\\shellwork\\devtool\\setup\\music\\setup.bat")
- from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
- device = MonkeyRunner.waitForConnection()
- #device.removePackage ('ApiDemos.apk')
- device.removePackage ('com.example.android.notepad')
- print ('卸载成功')
- MonkeyRunner.sleep(15)
- device.installPackage('ApiDemos.apk')
- print ('安装成功')