0

The versionName "JNMILLER" won't delete. Any idea why it's not finding the name?

Terminal:

================= RESTART: C:\Users\jnmiller\Desktop\test.py 
=================
Found - "EGAS\JMEESE"
Found - "EGAS\MWETZEL"
Found - SDE
Found - sde
Found - "EGAS\JNMILLER"
Found - "EGAS\SCRAWFORD"
Found - "EGAS\CCOON"
Done
>>> 

Code:

# Name: DeleteVersion.py
# Description: Deletes a version

# Import system modules
import arcpy

# Set local variables
arcpy.env.workspace = "Database Connections/NEO_1.sde"
connection = arcpy.env.workspace
versionName = "JNMILLER"

# Execute DeleteVersion
for version in arcpy.da.ListVersions(connection):
    print "Found - {0}".format(version.name.split(".")[0])
    if version.name.split(".")[0] == versionName:
        arcpy.DeleteVersion_management(connection, versionName)
        print("Deleting version {0}".format(version.name))

print("Done")

enter image description here

  • The owner is part of the name. If you're not the owner, you'll need to include it in the name (though it might not let you delete a version you dont own) – Vince Feb 22 '18 at 14:14
  • I might be writing this incorrectly since it doesn't work but is this what you're thinking: owner = "EGAS\JNMILLER" name = 'JNMILLER' versionUser = os.path.join(owner,".",name) versionName = versionUser An error doesn't generate but it doesn't run the tool either – Jordan Feb 22 '18 at 14:37
  • Backslash is a special character. You need to escape it or use raw string formatting. – Vince Feb 22 '18 at 22:24
  • Also, because the backslash is present, the name itself contains quotes. – Vince Feb 22 '18 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.