Skip to main content
deleted 10 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Arabella, areIf your featureclasses are in Feature Datasets? If so, @Aragon's solutionthen @Aragon's solution will not work because you need to walk through the feature datasets and then check the featureclasses.

Using @Aragon's code@Aragon's code as well as @gotchula's code from List all feature classes in GDB, including within feature datasets, I produced the following code that will read through all feature datasets and featureclassesfeature classes in a geodatabase.

NOTE: By default ListFields appears to be case-sensitive. I have added code to convert both the user-defined fieldname and the ListField name to lowercase for case-insensitive searches. You probably would also want to disable most of the print statements, but I left them in there so you can follow the code as it is running. I also created the sub-function FindField within the so that I could call it multiple times in the script without having to re-code it.

import arcpy

def FindField(fc,myField):
    fieldList = arcpy.ListFields(fc)
    for field in fieldList:
        if str.lower(str(field.name)) == str.lower(myField):
            print "    " + fc + " contains fieldname: " + myField

myField = "test"
arcpy.env.workspace = "D:/test/data.gdb"

#Search root level featureclasses
for fc in arcpy.ListFeatureClasses():
    print "Searching root level Featureclasses..."
    print "  Searching " + fc
    FindField(fc,myField)

#Search Feature Datasets
for fds in arcpy.ListDatasets('','feature'):
    print "Searching FeatureDataset: " + fds

    for fc in arcpy.ListFeatureClasses('','',fds):
        print "  Searching Featureclass... " + fc
        FindField(fc,myField)

Arabella, are your featureclasses in Feature Datasets? If so, @Aragon's solution will not work because you need to walk through the feature datasets and then check the featureclasses.

Using @Aragon's code as well as @gotchula's code from List all feature classes in GDB, including within feature datasets, I produced the following code that will read through all feature datasets and featureclasses in a geodatabase.

NOTE: By default ListFields appears to be case-sensitive. I have added code to convert both the user-defined fieldname and the ListField name to lowercase for case-insensitive searches. You probably would also want to disable most of the print statements, but I left them in there so you can follow the code as it is running. I also created the sub-function FindField within the so that I could call it multiple times in the script without having to re-code it.

import arcpy

def FindField(fc,myField):
    fieldList = arcpy.ListFields(fc)
    for field in fieldList:
        if str.lower(str(field.name)) == str.lower(myField):
            print "    " + fc + " contains fieldname: " + myField

myField = "test"
arcpy.env.workspace = "D:/test/data.gdb"

#Search root level featureclasses
for fc in arcpy.ListFeatureClasses():
    print "Searching root level Featureclasses..."
    print "  Searching " + fc
    FindField(fc,myField)

#Search Feature Datasets
for fds in arcpy.ListDatasets('','feature'):
    print "Searching FeatureDataset: " + fds

    for fc in arcpy.ListFeatureClasses('','',fds):
        print "  Searching Featureclass... " + fc
        FindField(fc,myField)

If your featureclasses are in Feature Datasets, then @Aragon's solution will not work because you need to walk through the feature datasets and then check the featureclasses.

Using @Aragon's code as well as @gotchula's code from List all feature classes in GDB, including within feature datasets, I produced the following code that will read through all feature datasets and feature classes in a geodatabase.

NOTE: By default ListFields appears to be case-sensitive. I have added code to convert both the user-defined fieldname and the ListField name to lowercase for case-insensitive searches. You probably would also want to disable most of the print statements, but I left them in there so you can follow the code as it is running. I also created the sub-function FindField within the so that I could call it multiple times in the script without having to re-code it.

import arcpy

def FindField(fc,myField):
    fieldList = arcpy.ListFields(fc)
    for field in fieldList:
        if str.lower(str(field.name)) == str.lower(myField):
            print "    " + fc + " contains fieldname: " + myField

myField = "test"
arcpy.env.workspace = "D:/test/data.gdb"

#Search root level featureclasses
for fc in arcpy.ListFeatureClasses():
    print "Searching root level Featureclasses..."
    print "  Searching " + fc
    FindField(fc,myField)

#Search Feature Datasets
for fds in arcpy.ListDatasets('','feature'):
    print "Searching FeatureDataset: " + fds

    for fc in arcpy.ListFeatureClasses('','',fds):
        print "  Searching Featureclass... " + fc
        FindField(fc,myField)
replaced http://gis.stackexchange.com/ with https://gis.stackexchange.com/
Source Link

Arabella, are your featureclasses in Feature Datasets? If so, @Aragon's solution will not work because you need to walk through the feature datasets and then check the featureclasses.

Using @Aragon's code as well as @gotchula's code from List all feature classes in GDB, including within feature datasetsList all feature classes in GDB, including within feature datasets, I produced the following code that will read through all feature datasets and featureclasses in a geodatabase.

NOTE: By default ListFields appears to be case-sensitive. I have added code to convert both the user-defined fieldname and the ListField name to lowercase for case-insensitive searches. You probably would also want to disable most of the print statements, but I left them in there so you can follow the code as it is running. I also created the sub-function FindField within the so that I could call it multiple times in the script without having to re-code it.

import arcpy

def FindField(fc,myField):
    fieldList = arcpy.ListFields(fc)
    for field in fieldList:
        if str.lower(str(field.name)) == str.lower(myField):
            print "    " + fc + " contains fieldname: " + myField

myField = "test"
arcpy.env.workspace = "D:/test/data.gdb"

#Search root level featureclasses
for fc in arcpy.ListFeatureClasses():
    print "Searching root level Featureclasses..."
    print "  Searching " + fc
    FindField(fc,myField)

#Search Feature Datasets
for fds in arcpy.ListDatasets('','feature'):
    print "Searching FeatureDataset: " + fds

    for fc in arcpy.ListFeatureClasses('','',fds):
        print "  Searching Featureclass... " + fc
        FindField(fc,myField)

Arabella, are your featureclasses in Feature Datasets? If so, @Aragon's solution will not work because you need to walk through the feature datasets and then check the featureclasses.

Using @Aragon's code as well as @gotchula's code from List all feature classes in GDB, including within feature datasets, I produced the following code that will read through all feature datasets and featureclasses in a geodatabase.

NOTE: By default ListFields appears to be case-sensitive. I have added code to convert both the user-defined fieldname and the ListField name to lowercase for case-insensitive searches. You probably would also want to disable most of the print statements, but I left them in there so you can follow the code as it is running. I also created the sub-function FindField within the so that I could call it multiple times in the script without having to re-code it.

import arcpy

def FindField(fc,myField):
    fieldList = arcpy.ListFields(fc)
    for field in fieldList:
        if str.lower(str(field.name)) == str.lower(myField):
            print "    " + fc + " contains fieldname: " + myField

myField = "test"
arcpy.env.workspace = "D:/test/data.gdb"

#Search root level featureclasses
for fc in arcpy.ListFeatureClasses():
    print "Searching root level Featureclasses..."
    print "  Searching " + fc
    FindField(fc,myField)

#Search Feature Datasets
for fds in arcpy.ListDatasets('','feature'):
    print "Searching FeatureDataset: " + fds

    for fc in arcpy.ListFeatureClasses('','',fds):
        print "  Searching Featureclass... " + fc
        FindField(fc,myField)

Arabella, are your featureclasses in Feature Datasets? If so, @Aragon's solution will not work because you need to walk through the feature datasets and then check the featureclasses.

Using @Aragon's code as well as @gotchula's code from List all feature classes in GDB, including within feature datasets, I produced the following code that will read through all feature datasets and featureclasses in a geodatabase.

NOTE: By default ListFields appears to be case-sensitive. I have added code to convert both the user-defined fieldname and the ListField name to lowercase for case-insensitive searches. You probably would also want to disable most of the print statements, but I left them in there so you can follow the code as it is running. I also created the sub-function FindField within the so that I could call it multiple times in the script without having to re-code it.

import arcpy

def FindField(fc,myField):
    fieldList = arcpy.ListFields(fc)
    for field in fieldList:
        if str.lower(str(field.name)) == str.lower(myField):
            print "    " + fc + " contains fieldname: " + myField

myField = "test"
arcpy.env.workspace = "D:/test/data.gdb"

#Search root level featureclasses
for fc in arcpy.ListFeatureClasses():
    print "Searching root level Featureclasses..."
    print "  Searching " + fc
    FindField(fc,myField)

#Search Feature Datasets
for fds in arcpy.ListDatasets('','feature'):
    print "Searching FeatureDataset: " + fds

    for fc in arcpy.ListFeatureClasses('','',fds):
        print "  Searching Featureclass... " + fc
        FindField(fc,myField)
updated the script to search featureclasses at the root level.
Source Link
RyanKDalton
  • 23.2k
  • 17
  • 112
  • 180

Arabella, are your featureclasses in Feature Datasets? If so, @Aragon's solution will not work because you need to walk through the feature datasets and then check the featureclasses.

Using @Aragon's code as well as @gotchula's code from List all feature classes in GDB, including within feature datasets, I produced the following code that will read through all feature datasets and featureclasses in a geodatabase.

NOTE: By default ListFields appears to be case-sensitive. I have added code to convert both the user-defined fieldname and the ListField name to lowercase for case-insensitive searches. You probably would also want to disable most of the print statements, but I left them in there so you can follow the code as it is running. I also created the sub-function FindField within the so that I could call it multiple times in the script without having to re-code it.

import arcpy

myField =def "test"FindField(fc,myField):
arcpy.env.workspace = "D:/test/data.gdb"

for fds infieldList = arcpy.ListDatasetsListFields('','feature'fc):
    printfor "Searchingfield FeatureDatasetin fieldList: 
 " + fds

    for fcif instr.lower(str(field.name)) arcpy== str.ListFeatureClasseslower('','',fdsmyField):
            print "  Searching Featureclass... " + fc + " contains fieldname: " + myField

myField = "test"
arcpy.env.workspace = "D:/test/data.gdb"

#Search root level featureclasses
for fieldListfc =in arcpy.ListFieldsListFeatureClasses(fc):
       print for"Searching fieldroot inlevel fieldList:Featureclasses..."
    print "  Searching " + fc
   if str.lower(strFindField(field.name)fc,myField)

#Search ==Feature strDatasets
for fds in arcpy.lowerListDatasets(myField'','feature'):
    print "Searching FeatureDataset: " + fds

    for fc in arcpy.ListFeatureClasses('','',fds):
        print "  Searching Featureclass... " + fc 
 + " contains fieldname: " +  FindField(fc,myField)

Arabella, are your featureclasses in Feature Datasets? If so, @Aragon's solution will not work because you need to walk through the feature datasets and then check the featureclasses.

Using @Aragon's code as well as @gotchula's code from List all feature classes in GDB, including within feature datasets, I produced the following code that will read through all feature datasets and featureclasses in a geodatabase.

NOTE: By default ListFields appears to be case-sensitive. I have added code to convert both the user-defined fieldname and the ListField name to lowercase for case-insensitive searches. You probably would also want to disable most of the print statements, but I left them in there so you can follow the code as it is running.

import arcpy

myField = "test"
arcpy.env.workspace = "D:/test/data.gdb"

for fds in arcpy.ListDatasets('','feature'):
    print "Searching FeatureDataset: " + fds

    for fc in arcpy.ListFeatureClasses('','',fds):
        print "  Searching Featureclass... " + fc

        fieldList = arcpy.ListFields(fc)
        for field in fieldList:
             if str.lower(str(field.name)) == str.lower(myField):
                 print "    " + fc + " contains fieldname: " + myField

Arabella, are your featureclasses in Feature Datasets? If so, @Aragon's solution will not work because you need to walk through the feature datasets and then check the featureclasses.

Using @Aragon's code as well as @gotchula's code from List all feature classes in GDB, including within feature datasets, I produced the following code that will read through all feature datasets and featureclasses in a geodatabase.

NOTE: By default ListFields appears to be case-sensitive. I have added code to convert both the user-defined fieldname and the ListField name to lowercase for case-insensitive searches. You probably would also want to disable most of the print statements, but I left them in there so you can follow the code as it is running. I also created the sub-function FindField within the so that I could call it multiple times in the script without having to re-code it.

import arcpy

def FindField(fc,myField):
    fieldList = arcpy.ListFields(fc)
    for field in fieldList: 
        if str.lower(str(field.name)) == str.lower(myField):
            print "    " + fc + " contains fieldname: " + myField

myField = "test"
arcpy.env.workspace = "D:/test/data.gdb"

#Search root level featureclasses
for fc in arcpy.ListFeatureClasses():
    print "Searching root level Featureclasses..."
    print "  Searching " + fc
    FindField(fc,myField)

#Search Feature Datasets
for fds in arcpy.ListDatasets('','feature'):
    print "Searching FeatureDataset: " + fds

    for fc in arcpy.ListFeatureClasses('','',fds):
        print "  Searching Featureclass... " + fc 
        FindField(fc,myField)
Source Link
RyanKDalton
  • 23.2k
  • 17
  • 112
  • 180
Loading