AnsweredAssumed Answered

Overwrite of output not working

Question asked by jaxelrodmfa on Sep 10, 2012
Latest reply on Oct 24, 2012 by curtvprice
I have a script that writes .dbf files to a folder. The first time the script runs it does what it is supposed to. The second time I run it however, it says the first .dbf to be created already exists and stops. It's not overwriting the files.
I have arcpy.env.overwriteOutput = True and had it successfully working to overwrite at one point in the development of the script. I'm not sure what made it stop working. I'm pretty sure I added the field mapping and the listing of the files in the log file after it was running smoothly but, have commented them out and it still gives me the error message. Any suggestions would be appreciated....I have no idea what is causing the problem.

# Import arcpy module
import arcpy, sys, traceback, time, datetime, os

# Set overwrite option
arcpy.env.overwriteOutput = True

# INPUT NEEDED: Set Read me file workspace
logpath = "X:\\Script\Out\ReadMe"
logfile1 = logpath + str (" ") + str(CURDATE) + ".txt"

if arcpy.Exists(logfile1):

log1 = open(logfile1, "a")

print "Generate Readme file " + str(CURDATE)
print >> log1, time.strftime("%c")
print >> log1, "End Processing "

#Set the current workspace for input file geodatabase
arcpy.env.workspace = "X:\\Script\Input.gdb"

#Set Local variables specifyting the output table folder:
outTable = "X:\\Script\Out"

print "Start Processing"

#Set a Search Cursor on the Polygons
srows = arcpy.SearchCursor("Polygons", "","", "WATERSHED", "" )
srow =

print "Get Polygon"

mapFields = ["ID", "STUDY", "NAME"]
fieldMappings = arcpy.FieldMappings()
for mapField in mapFields:
    fieldMap = arcpy.FieldMap()
    fieldMap.addInputField("Points", mapField)

while srow:

    pid = srow.ObjectID
    poly_lyr = arcpy.MakeFeatureLayer_management("Polygons",'pgon_select',""" "ObjectID" = """+ str(pid))
    print "Watershed is " + str(srow.WATERSHED)
    arcpy.MakeFeatureLayer_management("Points", "Points_lyr", "", "",  )
    print "Make point feature layer"

    arcpy.SelectLayerByLocation_management("Points_lyr", "INTERSECT", "pgon_select", "", "NEW_SELECTION")
    print "Select points by " + str(srow.WATERSHED) + " watershed"

    arcpy.TableToTable_conversion("Points_lyr", outTable , str(srow.WATERSHED)+ ".dbf","")
    print "Make table " + str(srow.WATERSHED)
    srow =
    print "Next Polygon"

print "Write .dbf tables to log file"
print >> log1, "Files generated = "
file_list = os.listdir(outTable)
for file in file_list:
    if file.endswith (".dbf"):
        log1.write(file + "\n")

print "End Processing"