0

I found this code here. first time I ran it, it copied my file to another folder but for second time nothing happened. Even I didn't get error in Jupyter Notebook.

#Move GDB to G: for your project's folder

src = r'folder_1'
dst = r'folder_2'

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

I don't have access to ArcPy in my PC. I need something which works without ArcPy and for Python 3.

  • 1
    A file geodatabase is a directory with many files which represent zero or more tables. Simple filesystem calls can work to move an entire file geodatabse, but not a single FGDB table. – Vince Dec 20 '19 at 16:50
  • 1
    Since a file geodatabase is just a folder of files so if you are stuck copying a folder using pure Python then the place to research/ask is Stack Overflow. – PolyGeo Dec 20 '19 at 20:10
1

This is basically a port of your code to Python3, don't think it matters that you're working with FGDB's:

#Move GDB to G: for your project's folder

src = r'folder_1'
dst = r'folder_2'

import shutil

def copyanything(src, dst):
    try:
        shutil.copytree(src, dst)
    except NotADirectoryError as e:
        shutil.copy(src, dst)

Shouldn't need the errno check as the raised error is specific enough in python3.

| improve this answer | |

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