delete multiple rasters in stand-alone Python script

2713
2
10-09-2013 06:42 AM
RayJahncke
New Contributor
Is it possible to use delete_management with a wildcard?

i.e. I want to delete all rasters that start with say "aPrefix_" in a workspace.
Or do I need to make a list and then loop through that list?

Many thanks.
Ray
Tags (2)
0 Kudos
2 Replies
StevenEnsing
New Contributor III
Hi Ray,
As you are guessing, the easiest way would be to create a list and then loop through the list of data. It's pretty straightforward. Some sample code would be:

import arcpy

workspace = r'c:\data'
arcpy.env.workspace = workspace

datasets = arcpy.ListFeatureClasses("prefix_*")
for dataset in datasets:
    arcpy.Delete_management(dataset)

print "done deleting datasets"


Of course, the arcpy List function would depend on what type of data you are looking for.
0 Kudos
RayJahncke
New Contributor
Perfect! Thanks Steven.
0 Kudos