ArcGIS Desktop

  • Documentation
  • Support

  • My Profile
  • Aide
  • Sign Out
ArcGIS Desktop

ArcGIS Online

La plateforme cartographique de votre organisation

ArcGIS Desktop

Un SIG professionnel complet

ArcGIS Enterprise

SIG dans votre entreprise

ArcGIS for Developers

Outils de création d'applications de localisation

ArcGIS Solutions

Modèles d'applications et de cartes gratuits pour votre secteur d'activité

ArcGIS Marketplace

Téléchargez des applications et des données pour votre organisation.

  • Documentation
  • Support
Esri
  • Se connecter
user
  • Mon profil
  • Déconnexion

ArcMap

  • Accueil
  • Commencer
  • Carte
  • Analyser
  • Gérer les données
  • Outils
  • Extensions

Walk

  • Résumé
  • Discussion
  • Syntaxe
  • Exemple de code

Résumé

Generate data names in a directory/database structure by walking the tree top-down or bottom-up. Each directory/workspace yields a tuple of three: directory path, directory names, and file names.

Discussion

Remarque :

The Walk function was made available at ArcGIS 10.1 Service Pack 1.

The Python os module includes an os.walk function that can be used to walk through a directory tree and find data. os.walk is file based and does not recognize database contents such as geodatabase feature classes, tables, or rasters. arcpy.da.Walk can be used to catalog data.

Syntaxe

Walk (top, {topdown}, {onerror}, {followlinks}, {datatype}, {type})
ParamètreExplicationType de données
top

The top-level workspace that will be used.

String
topdown

If topdown is True or not specified, the tuple for a directory is generated before the tuple for any of its workspaces (workspaces are generated top-down). If topdown is False, the tuple for a workspace is generated after the tuple for all of its subworkspaces (workspaces are generated bottom-up).

When topdown is True, the dirnames list can be modified in-place, and Walk() will only recurse into the subworkspaces whose names remain in dirnames. This can be used to limit the search, impose a specific order of visiting, or even to inform Walk() about directories the caller creates or renames before it resumes Walk() again. Modifying dirnames when topdown is Falseis ineffective, because in bottom-up mode the workspaces in dirnames are generated before dirpath itself is generated.

(La valeur par défaut est True)

Boolean
onerror

Errors are ignored by default. The onerror function will be called with an OSError instance.

The function can be used to report the error and continue with the walk or raise an exception to abort.

Remarque :

The file name is available as the filename attribute of the exception object.

(La valeur par défaut est None)

Function
followlinks

By default, Walk() does not walk into connection files. Set followlinks to True to visit connection files.

(La valeur par défaut est False)

Boolean
datatype

The data type to limit the results returned. Valid data types are the following:

  • Any —All data types are returned. Equivalent to using None or skipping the argument.
  • CadDrawing
  • CadastralFabric
  • Container
  • FeatureClass
  • FeatureDataset
  • GeometricNetwork
  • LasDataset
  • Layer
  • Locator
  • Map
  • MosaicDataset
  • NetworkDataset
  • PlanarGraph
  • RasterCatalog
  • RasterDataset
  • RelationshipClass
  • RepresentationClass
  • Style
  • Table
  • Terrain
  • Text
  • Tin
  • Tool
  • Toolbox
  • Topology

Multiple data types are supported if entered as a list or tuple.

for dirpath, dirnames, filenames in arcpy.da.Walk(workspace,
    datatype=['MosaicDataset', 'RasterDataset']):

(La valeur par défaut est None)

String
type

Feature and raster data types can be further limited by type.

  • All —All types are returned. Equivalent to using None or skipping the argument.
  • Any —All types are returned. Equivalent to using None or skipping the argument.

Valid feature types are the following:

  • Multipatch — Only multipatch feature classes are returned.
  • Multipoint —Only multipoint feature classes are returned.
  • Point —Only point feature classes are returned.
  • Polygon —Only polygon feature classes are returned.
  • Polyline —Only polyline feature classes are returned.

Valid raster types are:

  • BIL — Esri Band Interleaved by Line file
  • BIP — Esri Band Interleaved by Pixel file
  • BMP — Bitmap graphic raster dataset format
  • BSQ — Esri Band Sequential file
  • DAT — ENVI DAT file
  • GIF — Graphic Interchange Format for raster datasets
  • GRID — Esri Grid raster dataset format
  • IMG — ERDAS IMAGINE raster data format
  • JP2 — JPEG 2000 raster dataset format
  • JPG — Joint Photographic Experts Group raster dataset format
  • PNG — Portable Network Graphic raster dataset format
  • TIF — Tag Image File Format for raster datasets

Multiple data types are supported if entered as a list or tuple.

for dirpath, dirnames, filenames in arcpy.da.Walk(workspace,
    datatype='FeatureClass', type=['Polygon', 'Polyline']):

(La valeur par défaut est None)

String

Valeur renvoyée

Type de donnéesExplication
Generator

Yields a tuple of three that includes the workspace, directory names, and file names.

  • dirpath is the path to the workspace as a string.
  • dirnames is a list of names of subdirectories and other workspaces in dirpath.
  • filenames is a list of names of nonworkspace contents in dirpath.
Remarque :

Names in the lists include only the base name; no path components are included. To get a full path (which begins with top) to a file or directory in dirpath, do os.path.join(dirpath, name).

Exemple de code

Walk example 1

Use the Walk function to catalog polygon feature classes.

import arcpy
import os

workspace = "c:/data"
feature_classes = []

walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="Polygon")

for dirpath, dirnames, filenames in walk:
    for filename in filenames:
        feature_classes.append(os.path.join(dirpath, filename))
Walk example 2

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 = []

walk = arcpy.da.Walk(workspace, topdown=True, datatype="RasterDataset")

for dirpath, dirnames, filenames in walk:
    # 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))

Rubriques connexes

  • Créer des listes de données

ArcGIS Desktop

  • Accueil
  • Documentation
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

A propos d'Esri

  • A propos de la société
  • Carrières
  • Blog des initiés
  • Conférence des utilisateurs
  • Sommet des développeurs
Esri
Donnez-nous votre avis.
Copyright © 2018 Esri. | Confidentialité | Légal