Select to view content in your preferred language

How to delete all rasters created in a database?

4088
2
Jump to solution
11-15-2014 08:30 PM
SaraGhandehari
Deactivated User

Hello all,

I am new to Arcgis and python scripting ,

I have a database and I want to delete all temporary created rasters in it. Doe's anybody know how to perform this task by python code?

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

I haven't tested the code, but I guess this should work:

import arcpy

# settings

gdb = r"C:\Path\to\your\FileGeodatabase.gdb"

arcpy.env.workspace = gdb

# create a list of rasters in the folder

rasters = arcpy.ListRasters()

# loop through raster in list

for raster in rasters:

    try:

        arcpy.Delete_management(raster)

    except:

        print "Raster '{0}' could not be deleted".format(raster)

Kind regards, Xander

View solution in original post

0 Kudos
2 Replies
XanderBakker
Esri Esteemed Contributor

I haven't tested the code, but I guess this should work:

import arcpy

# settings

gdb = r"C:\Path\to\your\FileGeodatabase.gdb"

arcpy.env.workspace = gdb

# create a list of rasters in the folder

rasters = arcpy.ListRasters()

# loop through raster in list

for raster in rasters:

    try:

        arcpy.Delete_management(raster)

    except:

        print "Raster '{0}' could not be deleted".format(raster)

Kind regards, Xander

0 Kudos
SaraGhandehari
Deactivated User

Thank you Xander. The code works!

Sara

0 Kudos