1

I have multiple GDBs from an earlier process. Each GDB contains a single feature class (FC).

I want to copy (FeatureClassToFeatureClass) each FC into a "Main" GDB for later processing in a single place.

I thought nesting a for loop like below would work. It runs, but doesn't produce a result or an error, so it's unclear why it's not working.

I am using Python 2.7.14 in a Windows Server environment, running with ArcGIS Desktop Advanced (10.6).

#Import modules
import arcpy
import os
#Target GDB
outGDB = r"E:\Jamie_Temp\Main_GDB.gdb"
#LIBRARIES
#Set workspace
arcpy.env.workspace = r"E:\Jamie_Temp\Test_Files"
#Find GDBs
inGDB = arcpy.ListWorkspaces()
for gdb in inGDB:
 inFCs = arcpy.ListFeatureClasses()
 for fc in inFCs:
 arcpy.FeatureClassToFeatureClass_conversion(fc, outGDB, fc.strip("_point"))

The idea being here that it:

  1. Finds the name of all GDBs in the workspace and assigns them to inGDB
  2. Loops through each GDB found in inGDB and list the FCs inside, assigning them to inFCs
  3. Copy the FCs found to Main_GDB.gdb
Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Feb 8, 2021 at 10:27
2
  • As a general advice I would add a r before each path, e.g. r"E:\Jamie_Temp\Main_GDB.gdb" and I would not use spaces in paths, so change Test Files to TestFiles or Test_Files. This will probably not fix the issue, but it is worth a try at least! Commented Feb 8, 2021 at 10:37
  • Edited and tested, no difference I'm afraid Commented Feb 8, 2021 at 10:39

1 Answer 1

2

You're not going to find any inFCs as you're not setting arcpy.env.workspace to a gdb before calling arcpy.ListFeatureClasses() which looks in the current workspace.

Try (untested):

#Import modules
import arcpy
import os
#Target GDB
outGDB = r"E:\Jamie_Temp\Main_GDB.gdb"
#LIBRARIES
#Set workspace
arcpy.env.workspace = ws = r"E:\Jamie_Temp\Test_Files" # note setting "ws" var here
#Find GDBs
inGDB = arcpy.ListWorkspaces()
for gdb in inGDB:
 arcpy.env.workspace = os.path.join(ws, gdb)
 # Or if gdb is a full path
 # arcpy.env.workspace = gdb
 
 inFCs = arcpy.ListFeatureClasses()
 for fc in inFCs:
 arcpy.FeatureClassToFeatureClass_conversion(fc, outGDB, fc.strip("_point"))
answered Feb 8, 2021 at 11:02
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.