我正在尋找一種解決方案,用於在連接此設備後,將所有文件從硬盤驅動器上的特定目錄複製到我的android手機上的特定或非特定目錄。Python自動腳本文件傳輸
我希望這些文件在連接到計算機並運行.py文件後自動移動(或至少複製)到手機中。
我有Windows 7和蟒蛇2.7
我是從另外一個答案嘗試這一點,但我不明白,因爲有幾個解釋,因此我無法得到它的工作。
編輯:我已經想出瞭如何在文件夾之間傳輸文件,但我想要我的手機。那麼,如何解決我的系統錯誤,找不到我手機的路徑,這將解決我相信的問題。代碼工作正常,問題是路徑。
這裏是我的代碼:
import os
import shutil
sourcePath = r'C:\Users\...\What_to_copy_to_phone'
destPath = r'Computer\XT1032\Internal storage'
for root, dirs, files in os.walk(sourcePath):
#figure out where we're going
dest = destPath + root.replace(sourcePath, '')
#if we're in a directory that doesn't exist in the destination folder
#then create a new folder
if not os.path.isdir(dest):
os.mkdir(dest)
print 'Directory created at: ' + dest
#loop through all files in the directory
for f in files:
#compute current (old) & new file locations
oldLoc = root + '\\' + f
newLoc = dest + '\\' + f
if not os.path.isfile(newLoc):
try:
shutil.copy2(oldLoc, newLoc)
print 'File ' + f + ' copied.'
except IOError:
print 'file "' + f + '" already exists'
我很抱歉,我是極少數,但我想我已經解決了它。
好的,你的問題是什麼?你試過什麼了? –
@Eric Renouf我編輯了我的答案,這就是我正在嘗試的 – worer
現在,如果複製部分工作,那麼您的問題是自動檢測您的電話與Win7電腦的USB連接? – Rilwan