text: Create lists # Set the workspace. List all of the feature classes that start with 'G' # arcpycard and a data type, so only polygon feature classes that start with the letter G are in the resulting list:
  # Set the workspace. List all of the polygon feature classes that # start with 'G' # arcpy # arcpy a variety of ways. Lists are a versatile Python type and provide a number of methods (append, count, extend, index, insert, pop, remove, reverse, and sort) that can be used to manipulate and extract information.
  For instance, if you want to know how many feature classes you have in a workspace, you can use Python's built-in len function to provide that number.
  import arcpy arcpy.env.workspace = "c:/St_Johns/Shapefiles" fcs = arcpy.ListFeatureClasses() # Use Python's built-in function len to reveal the number of feature classes # in the workspace # fcCount = len(fcs) print fcCount
  A Python list can easily show its contents. Python lists can be manipulated with a number of methods, including sort, append, and reverse.
  >>> import arcpy >>> arcpy.
  Searching directories and subdirectories
  ArcPy list functions can be used to iterate over a single directory or workspace, but in some cases, iterating through other subfolders and workspaces is necessary. For files, this can be achieved with Python's os.walk function which is used to iterate or walk through folders to find additional subfolders and files. However, os.walk is strictly file based and does not recognize databases and non-file-based data types that are important in ArcGIS. For instance, os.walk will not see raster datasets or other contents in a file geodatabase workspace or a feature dataset.
  In the arcpy.da module, the Walk function can also be used to iterate through a directory tree but can also look into databases and identify ArcGIS data types.
  Unlike the List functions, Walk does not use the workspace environment to identify its starting workspace. Instead, the first starting (or top) workspace that Walk traverses is specified in its first argument, top.
  In the following example, the Walk function is used to iterate through a Catalog tree and identify all Polygon feature classes contained within.
  Use Walk function to catalog polygon feature classes.
  import arcpy import os workspace = "c:/data" feature_classes = [] for dirpath, dirnames, datatypes in arcpy.da.Walk(workspace, datatype="FeatureClass", type="Polygon"): # Append all Polygon feature classes to a list for further processing for datatype in datatypes: feature_classes.append(os.path.join(dirpath, filename))
  In some cases, there may be subdirectories that should be avoided when traversing the Catalog tree, for example, directories of backed-up files. If the topdown argument is True or unspecified, the workspaces can be modified in-place to avoid any undesired workspaces or to add additional workspaces as they are created.
  Use the Walk function to catalog raster data. Any rasters in a folder named back_up will be ignored.
  import arcpy import os workspace = "c:/data" rasters = [] for dirpath, dirnames, filenames in arcpy.da.Walk(workspace, topdown=True, datatype="RasterDataset"): # Disregard any folder named 'back_up' in creating list # of rasters if "back_up" in dirnames: dirnames.remove('back_up') for filename in filenames: rasters.append(os.path.join(dirpath, filename))
  Example: Using arcpy.da.Walk to analyze data
  The Walk function (as well as List functions) is commonly used for processing data in bulk. The following script takes advantage of the arcpy.da.Walk function to analyze all datasets in an SDE workspace.
  import arcpy import os # SDE workspace to be used admin_workspace = "Database Connections/tenone@sde.sde" analyze_contents = [] for dirpath, workspaces, datatypes in arcpy.da.Walk( admin_workspace, followlinks=True, datatype=['Table', 'FeatureClass', 'RasterDataset']): # Create full path, and add tables, feature classes, raster datasets analyze_contents += [ os.path.join(dirpath, datatype) for datatype in datatypes] # create full path, add the feature datasets of the .sde file analyze_contents += [ os.path.join(dirpath, workspace) for workspace in workspaces] # Execute Analyze Datasets on the complete list arcpy.AnalyzeDatasets_management(admin_workspace, "SYSTEM", analyze_contents, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")
  By default, sde connection files are not iterated to save from unintentional opening of remote databases. To deliberately iterate through an sde connection file, set the followlinks argument to True.