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:
- Finds the name of all GDBs in the workspace and assigns them to
inGDB
- Loops through each GDB found in
inGDB
and list the FCs inside, assigning them toinFCs
- Copy the FCs found to
Main_GDB.gdb
-
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!BritishSteel– BritishSteel2021年02月08日 10:37:06 +00:00Commented Feb 8, 2021 at 10:37
-
Edited and tested, no difference I'm afraidJClarkson– JClarkson2021年02月08日 10:39:45 +00:00Commented Feb 8, 2021 at 10:39
1 Answer 1
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"))