Gabe Weiner
Gabe Weiner

Reputation: 11

shutil.copytree --> [WinError 183]

I am trying to copy an entire directory to a newly created directory. When running this, it does everything correctly and to what I can see actually does copy everything from the source folder. However, it will still return [WinError 183] - Cannot create a file that already exists despite the fact that the file does not exist. Not sure what I'm doing wrong.

EDIT: After checking it is copying everything over before the error hits -- every file, every folder, so not sure what is going wrong

import os
import shutil

#Directory Definitions
root_dir = "C:\\Users\\Gabe Weiner\\Desktop\\GMImport" #os.getcwd()
source_dir = root_dir + "\source"
target_dir = root_dir + "\\target"

#Target Duplicate
for root, dirs, files in os.walk(str(target_dir)):
   shutil.copytree(root, root_dir + "\\Backup")

Upvotes: 1

Views: 1404

Answers (1)

Luca Di Sabatino
Luca Di Sabatino

Reputation: 139

Though this is not a shutil solution, alternatively you can use the following:

import os
from distutils.dir_util import copy_tree    <<<-----

def CopyFolder( in_fold, out_fold):
    copy_tree(in_fold, out_fold)     <<<<<<--------

#Directory Definitions
root_dir = r"C:\00_JOB\1_SVN\TullONE\4-Post_Production\t" #os.getcwd()
target_dir = root_dir + "\\target"

#Target Duplicate
for root, dirs, files in os.walk(target_dir):
    CopyFolder(root, root_dir + "\\Backup")      <<<<<<-----.

Upvotes: 1

Related Questions