<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic arcpy check to see if version exists in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-check-to-see-if-version-exists/m-p/157259#M12096</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey All,&lt;/P&gt;&lt;P&gt;I am having a hard time finding a method to check if a version exists.&amp;nbsp; If it exists, I would like to delete it and recreate it &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5;"&gt;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.&amp;nbsp; I Instead of expecting a failure condition and dealing with the fallout, I would rather have if: else: statements that look more like this&lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5;"&gt;. Can this be accomplished?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;import arcpy&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;import os&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;ws = os.path.join(os.environ['APPDATA'],"ESRI","Desktop10.2","ArcCatalog", "cfile" + ".sde")&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="line-height: 1.5;"&gt;vname = "iLOVEtacos"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;vowner = "SDE"&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;if arcpy.FindVersion(ws, vowner, vname):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.DeleteVersion_management(ws, vname)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="line-height: 1.5;"&gt;arcpy.CreateVersion_management(ws, "SDE.DEFAULT", vname, "PUBLIC")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Jun 2015 14:27:55 GMT</pubDate>
    <dc:creator>MattFrancis1</dc:creator>
    <dc:date>2015-06-15T14:27:55Z</dc:date>
    <item>
      <title>arcpy check to see if version exists</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-to-see-if-version-exists/m-p/157259#M12096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey All,&lt;/P&gt;&lt;P&gt;I am having a hard time finding a method to check if a version exists.&amp;nbsp; If it exists, I would like to delete it and recreate it &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5;"&gt;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.&amp;nbsp; I Instead of expecting a failure condition and dealing with the fallout, I would rather have if: else: statements that look more like this&lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5;"&gt;. Can this be accomplished?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;import arcpy&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;import os&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;ws = os.path.join(os.environ['APPDATA'],"ESRI","Desktop10.2","ArcCatalog", "cfile" + ".sde")&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="line-height: 1.5;"&gt;vname = "iLOVEtacos"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;vowner = "SDE"&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;if arcpy.FindVersion(ws, vowner, vname):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.DeleteVersion_management(ws, vname)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="line-height: 1.5;"&gt;arcpy.CreateVersion_management(ws, "SDE.DEFAULT", vname, "PUBLIC")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2015 14:27:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-to-see-if-version-exists/m-p/157259#M12096</guid>
      <dc:creator>MattFrancis1</dc:creator>
      <dc:date>2015-06-15T14:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy check to see if version exists</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-to-see-if-version-exists/m-p/157260#M12097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Matt,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could accomplish this with something similar below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
env.workspace = r"Database Connections\SQLSERVER.sde"

for version in arcpy.da.ListVersions(env.workspace):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if 'iLOVEtacos' in version.name:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.DeleteVersion_management(env.workspace, version.name)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:20:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-to-see-if-version-exists/m-p/157260#M12097</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T08:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy check to see if version exists</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-to-see-if-version-exists/m-p/157261#M12098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's a thing of beauty.&amp;nbsp; Thanks for your help!&lt;/P&gt;&lt;P&gt;Matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2015 15:52:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-to-see-if-version-exists/m-p/157261#M12098</guid>
      <dc:creator>MattFrancis1</dc:creator>
      <dc:date>2015-06-15T15:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy check to see if version exists</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-to-see-if-version-exists/m-p/157262#M12099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm glad you found a solution, Matt. Do you mind marking the question as answered? Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2015 17:14:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-to-see-if-version-exists/m-p/157262#M12099</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-06-15T17:14:43Z</dc:date>
    </item>
  </channel>
</rss>

