Create raster list by reading .tif files in multiple folders

3090
10
Jump to solution
09-13-2017 11:13 AM
DuminduJayasekera
New Contributor III

Hi,

I need to read multiple folders and read the .tif files and hold it a rasterlist. I have mycode below but it holds only last year tif. files.

Can somebody help me to read all the .tif files and hold in the raster list. ?

Thanks in advance.

Please see my code below:

years = [1981,1982,1983]
for year in years:
lstFiles = [] 
 arcpy.env.workspace = r'H:\PRISM_800m_weekly_sum' + "\\" + str(year)
 lstFiles = arcpy.ListRasters("*","TIF")
 for raster in lstFiles:
 print(raster)
 lstFiles.sort()‍‍‍‍‍‍‍‍


>>> lstFiles
[u'Week_1_Sum1983_10.tif', u'Week_1_Sum1983_11.tif', u'Week_1_Sum1983_9.tif', u'Week_2_Sum1983_10.tif', u'Week_2_Sum1983_11.tif', u'Week_2_Sum1983_9.tif', u'Week_3_Sum1983_10.tif', u'Week_3_Sum1983_11.tif', u'Week_3_Sum1983_9.tif', u'Week_4_Sum1983_10.tif', u'Week_4_Sum1983_11.tif', u'Week_4_Sum1983_9.tif', u'Week_5_Sum1983_10.tif', u'Week_5_Sum1983_11.tif', u'Week_5_Sum1983_9.tif']
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (4)
0 Kudos
10 Replies
DuminduJayasekera
New Contributor III

Thanks Dan.

0 Kudos