准备
- 手机开启开发者模式
- USB或wifi连接到电脑调试
- 电脑安装了
adb
,并配置了环境变量
Python代码
import os
import sys
import datetime
from shutil import copyfile
filePath = sys.argv[1]
def main():
print(filePath)
flag = is_contains_chinese(filePath)
if flag:
path = copy(filePath)
else:
path = filePath
print(path)
phoneDir = '/sdcard/Download'
cmd = ('adb push %s %s' % (path,phoneDir))
os.system(cmd)
if flag:
os.remove(path)
def copy(strs):
dirName = os.path.dirname(filePath)
print(dirName)
fileName = os.path.basename(filePath)
print(fileName)
ary = os.path.splitext(fileName)
if len(ary) > 1:
ext = ary[1]
else:
ext = ""
print(ext)
newName = datetime.datetime.now().strftime('%Y%m%d_%H%M%S') + ext
prePath = os.getcwd() + "\\" + newName
print(prePath)
copyfile(filePath, prePath)
return prePath
def is_contains_chinese(strs):
for _char in strs:
if '\u4e00' <= _char <= '\u9fa5':
return True
return False
if __name__ == '__main__':
main()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
添加到鼠标右键
- 打开注册表:
supre+R
输入regedit
,回车 HKEY_CLASSES_ROOT\*\shell
路径下,新建—项,输入adbPushFileToPhone
(可以自己随便改)adbPushFileToPhone
下新建—项,输入command
(必须,不能改)command
右侧,默认右键修改,数值数据输入:
D:\IT\Python3.x\python.exe D:\IT\PyExc\adbPushFileToPhone.py "%1"