I have a simple model in ModelBuilder that does the following:

  1. Iterate through a folder of rasters (these are outputs from Global Climate Models)
  2. Clip each raster to a study area (Egypt), using a polygon, and dump outputs into a Geodatabase
  3. For each clipped raster use the Zonal Statistics as Table tool to calculate some basic statistics (i.e. mean, min, max) and dump the outputs into a folder

Problem: There are many input rasters, each with similar names (i.e. Temp1, Temp2, Precip1, Precip2 etc.). This means that when running the model the outputs are all subsequently named very similarly such that I am unable to know which GCM each output has come from.

What I would like to do: Each input raster is stored in a folder with a name that I would like to retain in the output file names. I would like to include this name in the output of each clipped raster (step 2 above) and in the output of each statistic table (step 3 above).

Current model: Below is a screenshot of my current model. I understand that I need to use the Parse Path and Calculate Value tools to retain the folder name and pass this into the output file names but I do not know how to do this. Help!

enter image description here

Progress: Thus far I have the below. I can get it to include the originating folder name in the output files in the clipped raster but it's also including part of the parent folder too (i.e. ParentFolderName_FolderName rather than simply FolderName_%Name%_c).

enter image description here

  • I think it would be better (and easier) to use python for this. There are many examples on this site.
    – Bera
    Commented Oct 23, 2016 at 18:56
  • Agreed, although I don't know Python well enough to do this! I've updated the question above with my progress (second image).
    – veedub
    Commented Oct 23, 2016 at 20:06

2 Answers 2


A colleague had more success with a simpler model, here's the (working) solution:

enter image description here

Where, 'Parse Path' is used three times to extract two folder levels and the file name; this is then included (using %value(3)%_%name%) in the 'Zonal Statistics as Table' tool to dump the resultant outputs into a folder named in the correct convention.

Also, to speed things up a little, the 'Clip' procedure was removed and incorporated as an Environmental variable (as a Mask) of the 'Zonal Statistics as Table' tool. As there are lots of rasters (hundreds) this sped things up a little.

Finally, outside of ModelBuilder, to combine the resultant .dbf files into a single file Command Prompt was used such that:

  1. Windows Start Button | Run
  2. Type cmd and hit enter
  3. Go to the folder with the dbf files
  4. Type copy *.dbf all.txt and hit enter to copy all data in the files into all.txt.
  5. Type exit and hit enter to close the DOS window

I hope this helps anybody with the same issue. Shame I couldn't get the Python code working though! Note, you could achieve the latter step (combining multiple dbfs) a number of different ways, including VBA or Python. I've used Command Prompt here only as I'm more familiar with it.


This code splits the path at "\". To return the last x part(s) of the split path, use the following code in 'Calculate Value' as the expression. Leave the code block blank. Set output type to string. To get the last part of the path, change x to 1. To get the last 2 parts of the path joined with "_", change x to 2. (e.g. C:\string1\string2\string3 -- x=2 yields "string2_string3" and x=1 yields "string3")


To use this in your model, it will look like this: %output_value_c%_%name%

  • Thanks for your help although I couldn't get this to work. Replacing 'x' for 1 or 2 didn't seem to rectify the problem as it threw an error in the Calculate Value tool and produced an empty raster. A colleague had more success with a simpler model - I've updated the OP. Thanks for your time.
    – veedub
    Commented Oct 24, 2016 at 7:22
  • No worries. It worked when I tested it. I'm using ArcGIS 10.3.
    – jbalk
    Commented Oct 24, 2016 at 7:35
  • did you put this into the expression box? - "_".join('\%Value%'.split('\\')[len('\%Value%'.split('\\'))-1:])
    – jbalk
    Commented Oct 24, 2016 at 7:40
  • Yes. Replacing 'x' with '2' also appended the upper two folder levels such that: ParentFolder4_ParentFolder3_ParentFolder2_ParentFolder1 (I only wanted up to level 2).
    – veedub
    Commented Oct 24, 2016 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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