Friday, 13 February 2015

Copy file geodatabase using Python?


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?




Answer



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

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...