我试图创建一个小脚本,将用户文件夹复制到网络驱动器,当他们移动到新PC时。
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 :(得分:0)
您需要为每个文件夹
运行copytree
命令
for folder in copyfolders:
shutil.copytree(os.path.join("C:", "Users", user, folder),os.path.join("L:", user , "backup"))