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.
then there is the whole arcpy.ListFeatureClasses, ListRasters, Listwhatever if you need things specific to geodatabases etc.
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.