I am trying to check to see if a scratch File Geodatabase exist. If it does not, then create one.
If it does exist I would like to delete all Feature Classes in the scratch File Geodatabase.
In the code below, it will create a scratch File Geodatabase if one does not exist. However, if one exist, it attempts to create a scratch File Geodatabase, rather than delete the existing contents.
import arcpy arcpy.env.overwriteOutput = True arcpy.env.scratchWorkspace = r'C:\Users\topmypath' scratchWorkspace = arcpy.env.scratchWorkspace scratchGDB = 'scratchGDB.gdb' if not arcpy.Exists(scratchGDB): arcpy.CreateFileGDB_management(scratchWorkspace, scratchGDB) print "Scratch FileGDB created" else: if arcpy.Exists(scratchGDB): for fc in arcpy.ListFeatureClasses(scratchGDB): arcpy.Delete_management(fc) print "Scratch GBD cleared..."