[GIS] Converting multiple File geodatabase (.gdb) into multiple Personal geodatabase (.mdb)

arcpypython

Individually I will Export the gdb to XML Workspace then import that into the personnel geodatabase and all Domains go over fine. But…

Let's Say I have several file geodatabase in a folder and Each of the file geodatabase has 1 feature dataset name "URS" and rest are feature classes. "URS" Feature dataset has several feature class as well.

The task for me is to convert Multiple file geodatabase into multiple Personnel geodatabase without including "URS" Feature datasets. If the Geodatabase don't have "URS" Feature dataset or any other feature classes then the python program will create an empty personnel geodatabase.

I am using pyscripter and below mentioned concept is not workin for a single geodatabase. How can I convert multiple File geodatabase (.gdb) into multiple Personal geodatabase (.mdb)?

# Import system modules
import arcpy

# Set environment settings
arcpy.env.workspace = "I:\python\Multiplegdb"
print arcpy.env.workspace

# Set local variables
inFeatures = r'I:\python\Multiplegdb\ABC.gdb'
print inFeatures
outLocation = r'I:\python\Multiplegdb\ABC_Output.mdb'
print outLocation

# Execute TableToGeodatabase
arcpy.FeatureClassToGeodatabase_conversion(inFeatures, outLocation)

enter image description here

enter image description here

Best Answer

Here is one approach that performs the following actions:

  1. Create a new .mdb with old FGDB name, but in new workspace
  2. Find all FC's in FGDB--take into account empty FDS's
  3. Copy all FC's to .mdb

import arcpy, os

arcpy.env.workspace = r'C:\temp\inws'
inws = arcpy.env.workspace
outws = r'C:\temp\outws'

fgdb = arcpy.ListWorkspaces(workspace_type = "fileGDB")

counter = 1
for f in fgdb:
    # Define the output .mdb name
    name = os.path.basename(f).split(".")[0]

    # Create a new personal gdb (.mdb)
    arcpy.CreatePersonalGDB_management(outws, name)
    outgdb = os.path.join(outws, name + ".mdb")

    # Get the FC's in FDS and copy to .mdb
    arcpy.env.workspace = os.path.join(inws, f, "")
    fcs1 = arcpy.ListFeatureClasses()
    for fc in fcs1:
        arcpy.CopyFeatures_management(fc, os.path.join(outgdb, fc))

    # Get stand-alone FC's and copy to .mdb
    arcpy.env.workspace = os.path.join(inws, f, "URS")
    fcs2 = arcpy.ListFeatureClasses()
    # Make sure there are FC's in the FDS
    if fcs2 != None:
        for fc in fcs2:
            arcpy.CopyFeatures_management(fc, os.path.join(outgdb, fc))

    print "%s of %s workspaces converted" % (counter, len(fgdb))
    counter = counter + 1

print "Processing complete."