The following script converts all of the feature datasets and feature classes of a personal geodatabase to a new file geodatabase.
import arcpy, os
# Set the in and out workspaces
inws = r'C:\temp'
outws = r'C:\temp\outws'
# List the Access Databases
arcpy.env.workspace = inws
mdbs = arcpy.ListWorkspaces(workspace_type = "Access")
count = 1
for m in mdbs:
# Define output FGDB name
fgdb_name = os.path.basename(m).split(".")[0] + ".gdb"
# Create a new FGDB
arcpy.CreateFileGDB_management(outws, fgdb_name)
# Copy any FCs that are directly in personal geodatabase
arcpy.env.workspace = os.path.join(inws, m)
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
arcpy.CopyFeatures_management(fc, os.path.join(outws, fgdb_name, fc))
# Report on processing status
print "%s of %s personal databases converted to FGDB" % (count, len(mdbs))
count += 1
# List the feature dataset
arcpy.env.workspace = os.path.join(inws, m)
fds = arcpy.ListDatasets()
for f in fds:
# Determine FDS spatial reference
desc = arcpy.Describe(f)
sr = desc.spatialReference
# Copy FDS to FGDB
arcpy.CreateFeatureDataset_management(os.path.join(outws, fgdb_name), f, spatial_reference = sr)
# Copy the FCs to new FDS
arcpy.env.workspace = os.path.join(inws, m, f)
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
arcpy.CopyFeatures_management(fc, os.path.join(outws, fgdb_name, f, fc))