AnsweredAssumed Answered

Overwrite output in python?

Question asked by drycreekeng on Jul 31, 2020
Latest reply on Jul 31, 2020 by Nicholas.Klein-Baer_usfs

I am writing code to cycle through tile packages and publish them to ArcGIS Online. I have tried sticking "arcpy.env.overwriteOutput = True" in a few different places but it doesnt work. The code halts when it finds a duplicate in the output location (here AGOL). 


Please tell me where it is supposed to go, or if I should use something else like asking if the file exists first. 


from arcgis.gis import GIS
import os
import getpass
import arcpy
import sys

gis = GIS("xxx", "xxx", "xxx")
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'C:\Users\natb0\OneDrive -\GIS\GIS\Data\Dry_Creek\7000_CLS_Farms\drone_flight_072720\TilePackages'
workspace = arcpy.env.workspace

for p in arcpy.ListFiles("*"):
print (p[:-5])
data_file_location = workspace + "\\" + p
tile_package = { 'title': ('%s') % p[:-5], 'tags': 'Drone, Imagery', 'type': 'Tile Package'}
add_tile_package = gis.content.add(tile_package, data = data_file_location)
publish_tile_package = add_tile_package.publish()
arcpy.env.overwriteOutput = True
publish_tile_package.move(folder= 'Drone')