1

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, '*')
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Mar 13, 2016 at 8:40

1 Answer 1

2

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).

answered Mar 13, 2016 at 8:57
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.