How do I check whether a file with a user-defined prefix already exists, using the while loop and if it is a case to request another prefix?
[GIS] Checking whether file already exists using while loop with ArcPy
arcpyloop
arcpyloop
How do I check whether a file with a user-defined prefix already exists, using the while loop and if it is a case to request another prefix?
Best Answer
Use
arcpy.Exists()
Additionally, look into
arcpy.CreateUniqueName()
to generate a new output name if the one you want to use already existsBased on what I think your code is doing, try this:
This will add a suffix number to the end of your output name to make it unique if the output name already exists.
e.g. if
praefix = "roads"
andbuffer_size = 10
, androads10
already exists, thearcpy.CreateUniqueName()
will create a output name ofroads10_0
to make it unique.And to include a notice to the user that the filename is different: