我正在尝试创建自己的python脚本来备份Android images.i可以看到Android安装得很好,我可以使用nautilus来回移动文件但不能从CLI移植
CLI错误是“不支持操作”
hkhrais@Hkhrais:/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C006%5D/Phone/Download$ cp DSC03951.JPG /home/hkhrais/Desktop/
cp: cannot open ‘DSC03951.JPG’ for reading: Operation not supported
python代码
try:
shutil.copyfile('/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C006%5D/Phone/Download/DSC03951.JPG', "/home/hkhrais/Desktop/test")
except:
raise
Traceback (most recent call last):
File "scriptt.py", line 33, in <module>
main()
File "scriptt.py", line 18, in main
shutil.copyfile(img, "/home/hkhrais/Desktop/test")
File "/usr/lib/python2.7/shutil.py", line 82, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 95] Operation not supported: '/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C006%5D/Phone/Download/DSC03951.JPG'
Android 4.2.2 Python 2.7 Ubuntu 14.4
请问任何想法或替代方法吗?
答案 0 :(得分:1)
使用gvfs-copy
代替cp
。例如:
gvfs-copy "mtp://[usb:002,06]/Phone/Download/DSC03951.JPG" /home/hkhrais/Desktop/
为了在python中执行此命令,您可以使用os.system
:
import os
os.system('gvfs-copy "mtp://[usb:002,06]/Phone/Download/DSC03951.JPG" /home/hkhrais/Desktop/')
答案 1 :(得分:1)
尝试使用ptp(我在使用MTP时遇到了同样的错误),但PTP工作正常。从设置中你可以改变设备连接时android手机对你电脑的显示方式,android 5有两个选项,PTP和MTP。