Exists

Summary

Determines the existence of the specified data object. Tests for the existence of feature classes, tables, datasets, shapefiles, workspaces, layers, and files in the current workspace. The function returns a Boolean indicating if the element exists.

Syntax

Exists (dataset)
ParameterExplanationData Type
dataset

The name, path, or both of a feature class, table, dataset, layer, shapefile, workspace, or file to be checked for existence.

String
Return Value
Data TypeExplanation
Boolean

A Boolean value of True will be returned if the specified element exists.

Code Sample

Exists example

Check for existence of specified data object.

import arcpy
from arcpy import env

# Set the current workspace
# 
env.workspace = "C:/Data/MyData.gdb"

# Check for existance of the output data before running the Buffer tool.
# 
if arcpy.Exists("RoadsBuff"):
    arcpy.Delete_management("RoadsBuff")

try:
    arcpy.Buffer_analysis("Roads", "RoadsBuff", "100 meters")
    arcpy.AddMessage("Buffer complete")
except:
    arcpy.AddError(arcpy.GetMessages(2))

Related Topics


10/28/2011