Skip to main content

ListWorkspaces

汇总

返回当前工作空间中的工作空间列表。

讨论

必须先设置工作空间环境,然后才能使用多个列表函数,包括 ListDatasetsListFeatureClassesListFilesListRastersListTablesListWorkspaces

语法

ListWorkspaces({wild_card}, {workspace_type})

参数 说明 数据类型

wild_card

限制返回的结果。如果未指定某一值,则返回所有值。通配符不区分大小写。

符号

说明

示例

*

表示零个或多个字符。

Te* 可找到田纳西州和德克萨斯州。

*

workspace_type

The workspace type that will limit the results returned.

  • Coverage—Coverage workspaces will be returned.

  • FileGDB—File geodatabases (.gdb) will be returned.

  • Folder—Shapefile workspaces will be returned.

  • SDE—Enterprise databases (.sde) will be returned.

  • SQLite—SQLite databases (.sqlite, .gpkg) will be returned.

  • All—All workspaces will be returned. This is the default.

(默认值为 All)

String

返回值

数据类型 说明

String

该函数将返回包含工作空间名称的列表,该列表受 wild_cardworkspace_type 参数限制。

代码示例

ListWorkspaces 示例

压缩工作空间中的所有文件地理数据库。

import arcpy

arcpy.env.workspace = "c:/data"

# List all file geodatabases in the current workspace
workspaces = arcpy.ListWorkspaces("*", "FileGDB")

for workspace in workspaces:
    # Compact each geodatabase
    arcpy.management.Compact(workspace)