AnsweredAssumed Answered

Py.Problem

Question asked by spcoman on Feb 14, 2015
Latest reply on Mar 5, 2015 by spcoman

I am trying to write a code that will loop through a gdb listing all tables, rasters and featureclasses. It must also list all fields and their types in the featureclasses and print them. I can get everything to print properly with the exception of the ListField. Once I started playing with that command it went down hill. I think the problem lies in determining the dataset for the ListField to run through, I do not know how to tell the ListField to target every featureclass in the designated gdb.

 

import arcpy, os

 

 

### Set Workspace

##gdbpath = raw_input ('Enter File Full Pathname to Geodatabase')

##if arcpy.Exists(gdbpath):

##    print 'GDB Found'

##else:

##    exit('Invalid Pathname')

gdbpath = 'C:\Users\Stanton\Documents\GISProgramming\Database\Database\Corvallis.gdb'

arcpy.env.workspace = gdbpath

basepath = os.path.basename(gdbpath)

dirpath = os.path.dirname(gdbpath)

 

 

print '='*60

print '='*60

 

 

# GDB Name

print 'File Geodatabase Name: ' + basepath

 

 

#GDB Directory

print 'File Geodatabase Directory: ' + dirpath

 

 

# Number of Feature Classes

fcList = arcpy.ListFeatureClasses()

numberFC = len(fcList)

print 'Number of FeatureClasses: ' + str(numberFC)

 

 

# Number of Tables

tableList = arcpy.ListTables()

numberTables = len(tableList)

print 'Number of Tables: ' + str(numberTables)

 

 

# Number of Rasters:

rasterList = arcpy.ListRasters()

numberRasters = len (rasterList)

print 'Number of Rasters: ' + str(numberRasters)

 

 

 

 

print '='*60

print '='*60

 

 

#Table Names

tableName = tableList

if not tableName:

    print 'Tables:'

    print '\tNone\n'

else:

    print 'Tables:'

for fc in tableName:

    print '\t' + fc + '\n'

 

 

 

 

#Raster Names

rasterName = rasterList

if not rasterName:

    print 'Rasters:'

    print '\tNone\n'

else:

    print 'Rasters:'

for fc in rasterName:

    print '\t' + fc + '\n'

 

 

#FeaturClassNames and Field Names

fcName = fcList

if not fcName:

    print 'FeatureClasses:'

    print '\tNone\n'

else:

    print 'FeatureClasses:'

dataset = gdbpath

fieldName = arcpy.ListFields(dataset,'*','All')

for fc in fcList:

    print '\t' + fc + fieldName

Outcomes