I am writing a python script which deletes a file if it is present in a particular folder.
I want to be able to check if the file exists first, and if it exists I want to delete the file but if it doesn't exist I want to do nothing.
Anyone any ideas on this.
Solved! Go to Solution.
Check out this article. https://www.cyberciti.biz/faq/python-delete-remove-file-if-exists-on-disk/
Use arcpy...
arcpy.Exists.... http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-functions/exists.htm
then there is the whole arcpy.ListFeatureClasses, ListRasters, Listwhatever if you need things specific to geodatabases etc.
ie http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-functions/listfeatureclasses.htm
Just use Delete—Help | ArcGIS Desktop first thing. If the data set or file/folder exists, Delete takes care of business. If it doesn't exist, Delete still succeeds so there is no error to trap. The Result—Help | ArcGIS Desktop from Delete will include a warning if the file doesn't exist, but the operation still succeeds.
Thanks for the reply guys
A modification of Kevin's seemed to do the trick.