My script goes through sub folders in my main directory and based on a wildcard checks if a tiff file exists or not, if it exists then the file path is appended to the corresponding list. For example, all the tiff files with "*CRP.tif"
wildcard, in all the sub folders, go into CRP_List = []
. My current code is partially hard-coded, is there a way to make my code more generic? The individual lists i.e. the tiff path names are inputs to a raster mosaic tool which merges all the tiffs/rasters together..
import arcpy, os
#Raster Lists
CRP_List = []
FOR_List = []
INR_List = []
IR_List = []
MO_List = []
PAS_List = []
TCI_List = []
TCT_List = []
TG_List = []
WAT_List = []
WLF_List = []
WLO_List = []
WLT_List = []
arcpy.env.workspace = "D:/A__P6_FINAL_TIFFs"
for folder in arcpy.ListWorkspaces("*"):
folder_basename = os.path.basename(folder)
CoName = folder_basename.rsplit('_',1)[0]
env.workspace = os.path.join("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL")
for raster in arcpy.ListRasters("*_CRP.tif"):
if arcpy.Exists(raster):
CRP_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*FOR.tif"):
if arcpy.Exists(raster):
FOREST_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*_INR.tif"):
if arcpy.Exists(raster):
INR_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*_IR.tif"):
if arcpy.Exists(raster):
IR_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*_MO.tif"):
if arcpy.Exists(raster):
MO_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*_PAS.tif"):
if arcpy.Exists(raster):
PAS_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*_TCI.tif"):
if arcpy.Exists(raster):
TCI_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*_TCT.tif"):
if arcpy.Exists(raster):
TCT_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*_TG.tif"):
if arcpy.Exists(raster):
TG_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*_WAT.tif"):
if arcpy.Exists(raster):
WAT_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*_WLF.tif"):
if arcpy.Exists(raster):
WLF_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*_WLO.tif"):
if arcpy.Exists(raster):
WLO_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)
for raster in arcpy.ListRasters("*_WLT.tif"):
if arcpy.Exists(raster):
WLT_List.append("D:/A__P6_FINAL_TIFFs/" + CoName + "_FINAL/" + raster)