I am trying to select all rasters using arcpy.ListRasters within all folders of a directory using arcpy.da.Walk. I'm using arcMap 10.2.
An example portion of the code I have:
workspace = ("...")
output = ("...")
walk = arcpy.da.Walk(workspace, topdown=True, datatype= "RasterDataset", type = "TIF")
for dirpath, dirnames, filenames in walk:
for filename in filenames:
rasters = arcpy.ListRasters("*", "TIF")
print rasters
Doesn't work. It results in :
None
None
None
None
None
None
None
None
None
This works and lists all raster names, but what I need is a list of the raster that I'm able to use for further processing:
workspace = ("...")
output = ("...")
walk = arcpy.da.Walk(workspace, topdown=True, datatype= "RasterDataset", type = "TIF")
for dirpath, dirnames, filenames in walk:
for filename in filenames:
print filename
I'm trying to use ListRasters so that I can batch process those rasters. In most cases I could do something like:
import arcpy arcpy.env.workspace = (...)
rasters = arcpy.ListRasters("*", "TIF")
for raster in rasters: arcpy.BatchBuildPyramids_management(raster)
But in this case I have a lot of folders with rasters in each folder. I need to grab all those rasters into a raster list I can then batch process