overwriteOutput - beginner question

696
2
10-20-2011 09:55 AM
TimothieBiggs
New Contributor II
Hello -

I am trying to adapt a script I found on ArcGIS Resource Center (Thanks ArcGIS Resource Center!). The script exports a pdf from an mxd. Currently if a pdf already exists with the same name it is overwritten - I would like it NOT to do this.

The relevant line of code is:
arcpy.overWriteOutput = 1

I have tried combinations of the following but can't get this to work:
changed 1 to 0
changed 1 to False
changed case of function to overwriteOutput
changed to arcpy.env

I also noticed that in the ArcMap Python interactive window if I type in arcpy.env.o to get the correct syntax/help both overWriteOutput and overwriteOutput are listed and in the help window one produces the word True and the other False!

Going slightly crazy now!

Can anyone tell me what I am doing wrong or suggest another way to stop the file being overwritten.

Thanks
Tim
Tags (2)
0 Kudos
2 Replies
AndrewChapkowski
Esri Regular Contributor
You can use conditional statements to check if a file exists:
import os
import arcpy
file = r"somepath\pdf.pdf"
if os.path.isfile(file): # exists - get a new name for the pdf
   file = arcpy.CreateUniqueName(file)

The if state basically is saying if the file exists and the os.path.isfile() returns true, then call this ArcPy function that will create a unique name for your file.

Also, to set overwrite output it should be:
arcpy.env.overwriteOutput = True # or 1
0 Kudos
TimothieBiggs
New Contributor II
Super. Thanks Andrew!
0 Kudos