Hey All,
I am having a hard time finding a method to check if a version exists. If it exists, I would like to delete it and recreate it
Currently my script uses an inelegant try: except: block, because I don't know how to check to see if a version named "iLOVEtacos" exists. I Instead of expecting a failure condition and dealing with the fallout, I would rather have if: else: statements that look more like this. Can this be accomplished?
import arcpy
import os
ws = os.path.join(os.environ['APPDATA'],"ESRI","Desktop10.2","ArcCatalog", "cfile" + ".sde")
vname = "iLOVEtacos"
vowner = "SDE"
if arcpy.FindVersion(ws, vowner, vname):
arcpy.DeleteVersion_management(ws, vname)
arcpy.CreateVersion_management(ws, "SDE.DEFAULT", vname, "PUBLIC")
Thanks,
Matt
Solved! Go to Solution.
Hi Matt,
You could accomplish this with something similar below:
import arcpy from arcpy import env env.workspace = r"Database Connections\SQLSERVER.sde" for version in arcpy.da.ListVersions(env.workspace): if 'iLOVEtacos' in version.name: arcpy.DeleteVersion_management(env.workspace, version.name)
Hi Matt,
You could accomplish this with something similar below:
import arcpy from arcpy import env env.workspace = r"Database Connections\SQLSERVER.sde" for version in arcpy.da.ListVersions(env.workspace): if 'iLOVEtacos' in version.name: arcpy.DeleteVersion_management(env.workspace, version.name)
That's a thing of beauty. Thanks for your help!
Matt
I'm glad you found a solution, Matt. Do you mind marking the question as answered? Thanks!