Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';难道你不想用python复制文件夹及其内容吗?_Python - Fatal编程技术网

Can';难道你不想用python复制文件夹及其内容吗?

Can';难道你不想用python复制文件夹及其内容吗?,python,Python,我已经看了1-2个小时的大量帖子和事情,我找不到解决办法。我正在尝试使用shutil.copytree(),但它使文件夹出错,然后抛出错误“FileExistError:[WinError 183]无法创建文件,而该文件已存在:'C:\Users\user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\background'? 我也不完全清楚为什么我的计划是这样的 import shutil import ctypes

我已经看了1-2个小时的大量帖子和事情,我找不到解决办法。我正在尝试使用shutil.copytree(),但它使文件夹出错,然后抛出错误“FileExistError:[WinError 183]无法创建文件,而该文件已存在:'C:\Users\user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\background'? 我也不完全清楚为什么我的计划是这样的

import shutil
import ctypes
import random
import getpass
import os
username = str(getpass.getuser())
target_images_path = r"C:\Users\{}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\background".format(username)
if not os.path.exists(target_images_path):
    os.makedirs(target_images_path)
target_path = r"C:\Users\{}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup".format(username)
shutil.copy("main.exe", target_path)
shutil.copytree('background', target_images_path)

请参阅另一个相关问题中@atzz的
dirs\u exist\u ok
argumenttry谢谢迈克,这样行吗?像它复制文件夹和东西没有问题,但由于某种原因,文件夹是epty