Skip to content

Instantly share code, notes, and snippets.

@mu88
Created March 1, 2018 16:09
Show Gist options
  • Save mu88/4bc579c51d013e8ec429bdf5f8426be0 to your computer and use it in GitHub Desktop.
Save mu88/4bc579c51d013e8ec429bdf5f8426be0 to your computer and use it in GitHub Desktop.
ArcPy - List all Object Classes of all File Geodatabases within a given directory
import arcpy, codecs, csv, os, shutil
os.system("cls")
origFgdbLocation = r"\\Server\Share"
origFgdbNames = ["A", "B", "C"]
csvFilePath = r"C:\temp\members.csv"
elements = []
for fgdbName in origFgdbNames:
print "Start FGDB '" + fgdbName + "'"
origFgdbPath = origFgdbLocation + os.path.sep + fgdbName + ".gdb"
arcpy.env.workspace = origFgdbPath
for fds in arcpy.ListDatasets():
print "Start feature dataset '" + fds + "'"
arcpy.env.workspace = os.path.join(origFgdbPath, fds)
fcls = arcpy.ListFeatureClasses()
tables = arcpy.ListTables()
for fcl in fcls:
currentElement = [fgdbName, fds, fcl, "fcl"]
elements.append(currentElement)
for table in tables:
currentElement = [fgdbName, fds, table, "table"]
elements.append(currentElement)
arcpy.env.workspace = origFgdbPath
print "Finish feature dataset '" + fds + "'"
print "Start root feature classes"
arcpy.env.workspace = origFgdbPath
fcls = arcpy.ListFeatureClasses()
for fcl in fcls:
currentElement = [fgdbName, "", fcl, "fcl"]
elements.append(currentElement)
print "Finish root feature classes"
print "Start root tables"
tables = arcpy.ListTables()
for table in tables:
currentElement = [fgdbName, "", table, "table"]
elements.append(currentElement)
print "Finish root tables"
print "Finish FGDB '" + fgdbName + "'"
print "Finish all"
f = codecs.open(csvFilePath, "w", encoding="utf-8")
f.write("FGDB; Dataset; Element; Type\n")
for element in elements:
f.write(element[0] + "; " + element[1] + "; " + element[2] + "; " + element[3] + "\n")
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment