I have a directory folder of precipitation data; within this folder are subfolders for years 1901-2014. In each of these subfolders are 12 .asc grid files; each file represents a month of the year (i.e. Jan through Dec).

I am trying to create a model that will iterate through each of these subfolders and perform a calculation on the 12 grid files (for example: calculate total annual precipitation). I may want to perform other calculations, but for now would like to just have the model working.

I have tried the Iterate Workspace function with the Raster Calculator, and the Iterate Rasters function with the Raster Calculator, but could not get either to work how I wanted.

I also tried Iterate Rasters with Collect Values, and Cell Statistics - but that is also not working.

Below are the models I have tried:RastCalcCalcStats

  • Hi there, and welcome to GIS Stack Exchange. Based on "raster calculator" and "model builder" I've assumed that you're using ArcGIS Desktop, and have added tags accordingly. Feel free to delete the tags if that's not correct – Stephen Lead Dec 9 '14 at 22:32
  • Would you be able to edit your question to include a picture of your model that gets closest to doing what you want, please? Showing precisely what you have tried and where you are stuck is usually the best way to attract potential answerers. – PolyGeo Dec 9 '14 at 23:06

When faced with a problem like this I use os.walk() which returns all files and then see if the files match what I want by extension, here's an example for shapefiles:

import sys, os, arcpy
InFolder = sys.argv[1]

for (path, dirs, files) in os.walk(InFolder):
    for ThisFile in files:
        fName,fExt = os.path.splitext(ThisFile)
        if fExt.upper() == ".SHP":
            fc = path + "\\" + ThisFile

Change fExt.upper() == ".SHP": to fExt.upper() == ".ASC": and then operate as normal with fc being the full path to the dataset.

The other option is to put all the rasters in manually... or semi manually:

Open a command prompt in your base folder and type:


Which gives a list of all the ASCII files in all subfolders... if there's too many to select then try piping to a text file:

DIR *.ASC /B/S > ASC_File_List.txt

Then select all, copy, and paste into the tool.


To get the Collect Values model to work on individual subfolders you'll need to make use of another submodel nested within your . Make a model with the Iterate Workspaces iterator in it with recursive set to false. Then modify your second model so that it requires the workspace (i.e. the subfolder) as a parameter, and feed the workspace from the main model into the Iterate Rasters operation. The main model will then perform all the calculations you want on each folder in sequence. Just make sure to set your variables so that the output file name is either kept in the same folder or named something that is path-dependent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.