Hi, I am doing something similar, but I have a directory with 11 folders each containing 7 .tif layers to be combined. I tried using os.walk to go through all the folders in the directory and was able to append each folder's content into a rasterList (I emptied the list between each folder). I'm having trouble getting the tool to run on all 7 .tif files in the list. I am posting what I started with before I found this post, and then the after what I tried. In the first code I was trying to get the rasterList into the in_rasters format ex.("band1.tif; band2.tif; band3.tif") in case that was causing the tool not to run. Any help would be awesome!import arcpy, os
#arcpy.env.workspace = "C:/Test"
arcpy.env.overwriteOutput = True
myDir = arcpy.GetParameterAsText(0)
bands = []
#?myDownloads = os.listdir(myDir)
try:
#Walk through directories
for root, dirs, files in os.walk(myDir):
arcpy.env.workspace = root
for f in files:
if f.endswith(".TIF"):
bands.append(f)
#print bands
a = ','.join(bands)
b = a.replace(",",";")
#[f.replace(",", ";") for f in bands]
arcpy.CompositeBands_management(b, f[:-7] + ".img")
print bands
bands=[]
print b
except:
print "Tool did not run"
print arcpy.GetMessages()
and after:import arcpy, sys, os
from arcpy import env
from arcpy.sa import *
arcpy.env.overwriteOutput = True
path_images = "C:/test" #arcpy.GetParameterAsText(0)
rasterList = []
for root, dirs, files in os.walk(path_images):
for name in files:
bands = os.path.join(root,name)
#print bands
if bands.endswith(".TIF"):
rasterList.append(bands)
tilename = name[0:-7]
#print tilename + " is being processed."
print rasterList
out_raster = path_images + "\\" + tilename + ".img"
print out_raster
#arcpy.CompositeBands_management(rasterList, out_raster)
rasterList = []
print rasterList