Export Geodatabase Contents to Text File?

4388
6
Jump to solution
05-25-2012 07:50 AM
JoshuaDamron
Occasional Contributor III
For organizational purposes I'm trying to organize feature class names in an Excel file.  Is there a way to export the feature class names/contents of a Geodatabase to a Text file? 

If so it will save a lot of time spent recreating the file names.

Thanks in advance!
1 Solution

Accepted Solutions
TimHopper
Occasional Contributor III
Hmmm...

Perhaps I accidentally create the toolbox at v10.1?  I'm surprised nobody else commented.

I re-created the toolbox at v10.0, seems to work fine for me.  Hopefully it works for you as well.

There are three parameters.

1. Output folder (windows folder)
2. Output text file name (such as MyOutputFile)
3. Input geodatabase

View solution in original post

6 Replies
TimHopper
Occasional Contributor III
Joshua,

Python will do this for you quite easily.  Try something like the following:

import arcpy

# create or open an existing text file
f = open("c:\\data\\fc_list.txt", "a")

# specify the geodatabase you want to retrieve feature classes from
gdb = "c:\\data\\MyGeodatabase.gdb"

# set your environment workspace
arcpy.env.workspace = gdb

#list all of the feature datasets within the geodatabase
datasetList = arcpy.ListDatasets("*")

# within each feature dataset, list the feature classes and write them to the text file
for dataset in datasetList:
 fcList1 = arcpy.ListFeatureClasses("*","",dataset)
 for fc in fcList1:
  f.write(fc + "\n")

# find all of the feature classes which do not reside within a feature dataset
fcList2 = arcpy.ListFeatureClasses("*")

# write the feature class names to the text file which don't reside in the feature dataset
for fc in fcList2:
 f.write(fc + "\n")
TimHopper
Occasional Contributor III
I modified the script a little bit and threw it in a toolbox as a script tool for you so you can see how it all gets put together.

import arcpy, os

outputDir = arcpy.GetParameterAsText(0)
outputName = arcpy.GetParameterAsText(1)
gdb = arcpy.GetParameterAsText(2)

textFile = (outputDir + os.sep + outputName + ".txt")

f = open(textFile, "a")

arcpy.env.workspace = gdb

datasetList = arcpy.ListDatasets("*")

for dataset in datasetList:
 fcList1 = arcpy.ListFeatureClasses("*","",dataset)
 for fc in fcList1:
  f.write(fc + "\n")

fcList2 = arcpy.ListFeatureClasses("*")

for fc in fcList2:
 f.write(fc + "\n")
CharlesBanks1
New Contributor II
Hi Tim,

I tried your Toolbox but there are no contents. Could you please elaborate on how to get it to work? What are the parameters, etc.

Thanks!
0 Kudos
TimHopper
Occasional Contributor III
Hmmm...

Perhaps I accidentally create the toolbox at v10.1?  I'm surprised nobody else commented.

I re-created the toolbox at v10.0, seems to work fine for me.  Hopefully it works for you as well.

There are three parameters.

1. Output folder (windows folder)
2. Output text file name (such as MyOutputFile)
3. Input geodatabase
CharlesBanks1
New Contributor II
Thanks, I am using v10.0 with SP4. Iwill try this.
0 Kudos
CharlesBanks1
New Contributor II
Hey, Tim, it worked!! It seems to work only for File GDB though. When I try to bring in a SDE GDB it seems not to be connecting to SDE.

Thanks,
0 Kudos