8

I am trying to copy fgdb from one path to another using Python.

copy(base.gdb,dest)

And got the message:

Error Info: 
[Errno 13] Permission denied:

How to fix it?

24

As far as a file system is concerned, a file gdb is a directory - trying to copy one as a single file will not work. Try this out:

import shutil, errno

def copyanything(src, dst):
    try:
        shutil.copytree(src, dst)
    except OSError as exc: # python >2.5
        if exc.errno == errno.ENOTDIR:
            shutil.copy(src, dst)
        else: raise
  • Yeap. that's it. copytree works, just copy does not. Tnx:) – Z77 May 6 '12 at 16:15
  • 2
    Important to note that copytree won't able to copy the file geodatabase contents if there are any .lock files there - you will get a permission denied error. The Copy GP tool will copy the geodatabase even if there are locks there (a user has open a feature class properties window or just navigate in the geodatabase in the Catalog window)! – Alex Tereshenkov May 25 '16 at 7:46
12

Another option:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000051000000

import arcgisscripting

gp = arcgisscripting.create()

gp.Copy_management(r"C:\test.gdb", r"C:\test_COPY.gdb")
  • 2
    arcpy.Copy_management(r"inPath", r"outPath") for the arcpy method (version 10 as opposed to 9.3) – Roy May 7 '12 at 13:08
  • Note: That when working over a Network this operation is very iffy. It will either, not work, work but report an 000260 Error, or if your lucky work with no errors. – Tristan Forward Mar 6 '14 at 22:11
5

Make sure that the person running the python script has permission to create additional folders in the directory the script is run from.

What type of system are you running the script on? Where in the PATH are you trying to run the script from?

1

i made a simple script to copy geodatabases in-sub folders.It runs quite well. Hope this helps

import sys, arcpy, os

input_folder = "pro_mdb"
output_folder = "file-geodatabase"
curr_file = os.getcwd()

pro_mdb = os.path.join(curr_file,input_folder)
fgeodatabase = os.path.join(curr_file,output_folder)
folders = os.listdir(pro_mdb)

for folder in folders:
    arcpy.env.workspace = os.path.join(pro_mdb,folder)
    filegdb = arcpy.ListWorkspaces("*","FileGDB")
    if len(filegdb) > 0:
        filegdb_name = os.path.basename(filegdb[0])
        ofgeodatabase = os.path.join(fgeodatabase,filegdb_name)
        if not arcpy.Exists(ofgeodatabase):
            try:
                arcpy.Copy_management(filegdb[0],ofgeodatabase)
                print "Da copy xong: %s" %(filegdb[0])
            except Exception as e:
                print e.message
        else:
            print "Da ton tai: %s" %(filegdb_name)
    else:
        print "Khong co FGB cua tinh %s" %(folder)
0

Pls. consider this in your python code. ( try to capture this error)

While doing manual copy of fGDB to another folder, pls. ensure you have not opened the fGDB in arcmap. It will throw an error "*.lock" file.

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.