I found an arcpy script for exporting all feature classes within a geodatabase, however, it is truncating the names to 26 character max. Features can be up to 160 characters, though the most I have is maybe 40 ... thanks end users. How do I get the full name out of the database.
Thanks!
ebay
import arcpy
# create or open an existing text file
f = open("c:\\temp\\fc_list.txt", "a")
# specify the geodatabase you want to retrieve feature classes from
gdb = "c:\\temp\\Tracks.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")
Solved! Go to Solution.
ID10T error ... Access was the culprit.
Not sure why that would be truncating the names.
I would do something more simple. Instead of writing to a text file, it just prints the results in the Python interpreter window where you can copy it wherever you want. From my testing in ArcGIS 10.2.2, it successfully prints feature class names longer than 26 characters.
import arcpy
# specify the geodatabase you want to retrieve feature classes from
gdb = r"c:\temp\Tracks.gdb"
# set your environment workspace
arcpy.env.workspace = gdb
# List all of the feature datasets and their feature classes
for ds in arcpy.ListDatasets():
print ds
for fc in arcpy.ListFeatureClasses("","",ds):
print "\t", fc
# List all of the other feature classes outside the feature datasets
for fc in arcpy.ListFeatureClasses():
print fc
EDIT:
Another solution would be this:
import arcpy
# Specify the geodatabase you want to retrieve feature classes from
gdb = r"c:\temp\Tracks.gdb"
# Set environment workspace
arcpy.env.workspace = gdb
# Get list of datasets
datasetList = arcpy.ListDatasets()
datasetList.append("") ##Add blank list item to catch feature classes not in a dataset
for ds in datasetList:
for fc in arcpy.ListFeatureClasses("","",ds):
print "{}\{}".format(ds, fc)
I'm also not sure where and why the name should be truncated. However, I would suggest to use arcpy.da.Walk(), simply because you do not have to start over and over again to find all the feature classes within the database.
import arcpy, os
f = open('C:/temp/fc_list.txt', 'a')
arcpy.env.workspace = r'C:/temp/Tracks.gdb'
for dirpath, dirnames, filenames in arcpy.da.Walk(arcpy.env.workspace, datatype='FeatureClass'):
for filename in filenames:
fc_path = os.path.join(dirpath, filename)
f.write(fc_path + '\n')
f.close()
If you don't need the complete path skip line 7 and exchange 'fc_path' in line 8 by 'filename'.
ID10T error ... Access was the culprit.