import arcpy from arcpy import env import os path = 'C:\\Data' env.workspace = path arcpy.management.CreateFileGDB(env.workspace,"Project","10.0") try: def fcs_in_workspace(workspace): env.workspace = workspace for fc in arcpy.ListFeatureClasses(): yield fc for ws in arcpy.ListWorkspaces(): for fc in fcs_in_workspace(os.path.join(workspace, ws)): yield fc OutGDB = env.workspace +'\\Project.gdb' for fc in fcs_in_workspace(env.workspace): arcpy.FeatureClassToGeodatabase_conversion(fc,OutGDB) print(fc +' copied.') except Exception as e: print(e) else: env.workspace = path arcpy.CompressFileGeodatabaseData_management(OutGDB) print(OutGDB + " has been compressed.")
Solved! Go to Solution.
import arcpy,os
from arcpy import env
path = 'E:\\GDBConversionProject\\2062 Cabin Bluff'
env.workspace = path
arcpy.management.CreateFileGDB(env.workspace,"Project","10.0")
try:
def fcs_in_workspace(workspace):
env.workspace = workspace
for fc in arcpy.ListFeatureClasses():
yield fc
for ws in arcpy.ListWorkspaces():
for fc in fcs_in_workspace(os.path.join(workspace, ws)):
if ws != path +"\\Project.gdb":
yield fc
OutGDB = env.workspace +'\\Project.gdb'
for fc in fcs_in_workspace(env.workspace):
arcpy.FeatureClassToGeodatabase_conversion(fc,OutGDB)
print(fc +' copied.')
except Exception as e:
print(e)
else:
env.workspace = path
print("Compressing FileGDB.")
arcpy.CompressFileGeodatabaseData_management(OutGDB)
print(OutGDB + " has been compressed.")
Question about the importance of this script:
Is this your companies (organization's) policy to convert shapefiles to file geodatabases?
Or is ESRI dictating this move because shapefiles are going to be deprecated in the near future?