I need to go through multi GDB in 1 folder and copy all feature classes from each GDB and copy them into the single GDB. I create a piece of python code that can go through each different GDB and also can access to all FCs in each GDB but, I can not copy them to the single GDB.
import arcpy, os
from arcpy import env
arcpy.env.overwriteOutput = True
# The folder that contain multi GDBs
env.workspace = r'C:\Users\Desktop\Polygon Created By Tool\Polygons For AutoA'
# New GDBs for output
output = r'C:\Users\Desktop\Polygon Created By Tool\Polygons\ALL POLYGONS.gdb'
gdbname=arcpy.ListWorkspaces()
for gdb_Name in gdbname:
env.workspace = gdb_Name
for fc in arcpy.ListFeatureClasses():
arcpy.MakeFeatureLayer_management(fc, fc+'new', '#', output, '*')
1 Answer 1
The line arcpy.MakeFeatureLayer_management(fc, fc+'new', '#', output, '*')
just makes an in-memory layer (similar to a layer in ArcMap table of contents).
Something like Feature Class to Feature Class should be used to copy feature classes to a new location.
gdbname=arcpy.ListWorkspaces()
for gdb_Name in gdbname:
env.workspace = gdb_Name
for fc in arcpy.ListFeatureClasses():
arcpy.FeatureClassToFeatureClass_conversion(fc, output, '{}_new'.format(fc) )
Also note that you haven't put in any checks for feature classes with the same name, so if any of the multiple GDBs contain feature classes with the same name you may get errors. An arcpy.Exists()
may be useful here (if duplicate names do exist).
Explore related questions
See similar questions with these tags.