Help with arcpy.Exists()

Discussion created by Xhosa on Jun 19, 2014
Latest reply on Jun 19, 2014 by Xhosa

I would like to use arcpy.Exists() to handle existing featureclasses in a file-GDB but am having a problem with the argument. The problem (for me) stems from splitting a single featureclass into 2 new layers into 2 separate geodatasets. ex. Layer1 becomes Layer1_A and layer1_B from attributes A and B and are placed into datasets A and B respectively. This is all good, but when I run the script again, the files would need to be either over written (arcpy.env.overwriteOutput = True) or ignored. So I turned to arcpy.Exists(). But since the select_analysis is running twice and adding '_A' and '_B' I am not sure how to handle the argument. Any help or suggestions are greatly appreciated!

Sample code:
for filename in filenames:
        if "TOD" in [f.name for f in arcpy.ListFields(os.path.join(dirpath, filename))]:
            if not arcpy.Exists(#Something to handle A and B):
                arcpy.Select_analysis(os.path.join(dirpath, filename), r"C:/testGDB.gdb/Layer_A/" + filename + "_A", '"TOD" = \'A\'')                
                arcpy.Select_analysis(os.path.join(dirpath, filename), r"C:/testGDB.gdb/Layer_B/" + filename + "_B", '"TOD" = \'B\'')
                print "Already exists"