2017-08-11 57 views
0

我想製作一個小的腳本,將用戶文件夾複製到聯網的驅動器,當他們移動到一臺新的PC時。複製與copytree的文件夾列表

import os, sys, shutil 

user = input("Enter user name: ") 
copyfolders = ['Desktop','Documents','Favorites'] 


shutil.copytree(os.path.join("C:", "Users", user, 
*copyfolders),os.path.join("L:", user , "backup")) 

我有越來越腳本在同一時間做一個文件夾目錄目前它的附加所有文件夾的名稱,像這樣的問題:

FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:Users\\user\\Desktop\\Documents\\Favorites' 

我不知道如何得到這個然而進入循環。

回答

0

你需要爲每個文件夾

for folder in copyfolders: 
    shutil.copytree(os.path.join("C:", "Users", user, folder),os.path.join("L:", user , "backup")) 
0
import os, sys, shutil 

user = input("Enter user name: ") 
copyfolders = ['Desktop','Documents','Favorites'] 

for folder in copyfolders: 
    shutil.copytree(os.path.join("C:", "Users", user, folder), os.path.join("L:", user , "backup")) 
運行 copytree命令