Seeking clarification on arcpy.Exists() and .ags paths

667
4
07-06-2021 06:32 PM
anonymous_geographer
New Contributor III

Hello everyone,

I am hoping to gain a better understanding of how arcpy.Exists() interprets an ArcGIS Server (.ags) connection file (currently using ArcGIS Pro 2.8.1)

After some testing, including the .ags file extension within the string variable will return False while excluding it will return True.

Examples:

 

import arcpy

test01 = arcpy.Exists("C:\\Path\\To\\Connection\\sample_ags_file.ags")
print(test01)
False

test02 = arcpy.Exists("C:\\Path\\To\\Connection\\sample_ags_file")
print(test02)
True

 

 

Could someone enlighten me as to why the .ags extension returns False?  Or is it bad practice to use arcpy.Exists() when attempting to verify the existence of .ags files?  I appreciate any clarification!

Tags (2)
4 Replies
DanPatterson
MVP Esteemed Contributor

 does arcpy.Describe 's dataType return.  Exists  will work for workspaces or files.

I don't have anything to check with


... sort of retired...
anonymous_geographer
New Contributor III

Good suggestion.

For "C:\\Path\\To\\Connection\\sample_ags_file", the dataType is shown as ServerConnection.

For "C:\\Path\\To\\Connection\\sample_ags_file.ags", the script errors out and says the file does not exist.

I'm assuming .ags extensions need to be excluded when using them with arcpy, but I'm unsure why that is the case if true.

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

or maybe something like 

import os.path
os.path.exists(file_path)


Think Location
0 Kudos
anonymous_geographer
New Contributor III

Yep I can confirm it exists with that (and will likely go that route), but I'm more curious about how .ags file extensions and arcpy.Exists() interact, since I'm seeing different results with/without the extension.

0 Kudos