Please find my script below currently all i'm wanting to do is iterate through a folder and any subfolders extracting anything that is a .gdb directory + its contents to a new folder.

import shutil, errno, re, os  

results = []
input_path = r"D:\Profiles\cdixon\Documents\BaseFolder"
output_path = r"D:\Profiles\cdixon\Documents\Extracted_GDBS"
for path, subdirs, files in os.walk(input_path):
    for dir_name in subdirs:
    if os.path.join(path, dir_name).endswith(".gdb") or os.path.join(path, dir_name).endswith(".GDB"):
                    print "Moving " + os.path.join(path, dir_name) + " To " + output_path
                    shutil.copytree(os.path.join(path, dir_name),    output_path) 

However when ran I get the error, despite the fact that the Extracted_GDBS folder is empty

WindowsError: [Error 183] Cannot create a file when that file already exists

If anyone has any ideas how I can fix this that would be great. I've seen some test scripts on here that kind of do what I'm looking for but given I'm not opening up any of the files or doing manipulation, aside from a copy/move, I think this should be ok without using any ESRI Arc libaries.

  • I think i remember, that copying caused this, because Python tries to create the directory with every file, in this case you can catch the exception and continue Feb 8, 2016 at 16:19
  • Ah great this appears to work, i was using copy simply for testing purposes. Is there any way to be able to enable copying? Feb 8, 2016 at 16:27

1 Answer 1


Omit the for loop and run copytree on the directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.