Question : Modify script to loop through all files in directories

Hello,

I think this script would work great if it would cycle through all the rasters in each of these folders and then save a new output raster for each iteration. Currently it justs goes the directory as listed I need it to cycle through all of the directories within my sys.argv[2] and sys.argv[3]

(a raster is directory containing several files that is recognized by ArcMap as a single unit or "file")

donut = sys.argv[2]
lc = sys.argv[3]

Each of these directories contains several other directories that are the input  rasters.

I would appreciate help to do this,
Thanks,
MJ
I am new to scripting and I would appreciate any help and annotation.

Thanks,
MJ
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
# Import system modules
import sys, string, os,  arcgisscripting
 
# Create the Geoprocessor object
gp = arcgisscripting.create()
 
# Check out any necessary licenses
gp.CheckOutExtension("spatial")
 
# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")
 
# Script arguments...
outRaster = sys.argv[1]
donut = sys.argv[2]
lc = sys.argv[3] 
 
InExpression = "CON(ISNULL(%s), %s, %s * -1)"%(sys.argv[2],sys.argv[3],sys.argv[3])
 
# Check out Spatial Analyst extension license
gp.CheckOutExtension("Spatial")
 
# Process: MapAlgebra
gp.SingleOutputMapAlgebra_sa(InExpression, outRaster)
Open in New Window Select All

Answer : Modify script to loop through all files in directories

to go through directories, use os.walk(). See the documentation for an example.
Random Solutions  
 
programming4us programming4us