In a precedent post Multiple Output for Zonal Statistics as Table I was trying to have as many table in the output as the rasters in the input. To overcome my errors, I decided to add a "Model Only Calculate Value" to the model. It looks like this:

enter image description here I think it's not the proper way to connect the "calculate value" but i didn't know how to do it properly. The error I have while running the model:

ERROR 000539: Error running expression: getFileName("C:\Users\fassi\Documents\Arcgis\NDVI_MODIS_per_decade")
Traceback (most recent call last):
  File "<expression>", line 1, in <module>
  File "<string>", line 4, in getFileName
WindowsError: [Error 123] La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte: 'C:\\Users\x0cassi\\Documents\\ArcGIS\\NDVI_MODIS_per_decade/*.*'

Failed to execute (Calculate Value).
  • Try adding an r in front of the filepath, but also note you're asking for the function to return within a loop; I expect you'll only get the first file encountered.
    – SMiller
    Commented May 21, 2019 at 13:42
  • Thanks.I have the same error with the r in front of the filepath. I do not know how to do my connections without the loop for this model.
    – Nour
    Commented May 21, 2019 at 13:51
  • if you open Python window print the result of os.listdir(path), what happens?
    – SMiller
    Commented May 21, 2019 at 14:22
  • It returns the files in the path (if I precise the path)
    – Nour
    Commented May 21, 2019 at 17:25
  • What specifically are you trying to do? The other question made it sound like you were trying to get unique output filenames. This Calculate Value tool won't do that. How are you using the output "Name" that comes from IterateRasters (teal circle)?
    – SMiller
    Commented May 21, 2019 at 18:03

3 Answers 3


Your path contains a form feed escape sequence - \f.

>>> "\f"

You need to use a raw string as your input. Raw strings ignore escape sequences.


Note the r before the start of the string.

  • Yes, that was my struggle also, thank you
    – Nour
    Commented May 21, 2019 at 21:10

Based on both linked questions, I understand the issue to be

  1. You want to perform Zonal Statistics as Table with multiple input rasters and multiple corresponding output tables.
  2. Your current process overwrites the output table for each raster, so you'd like to get a unique name for each output table.
  3. The previous question's comments led you to use the output of %name% from the Iterate Rasters step, which includes an extension of .tif from the raster filename; having this period in the name causes trouble with the output table.
  4. You tried CalculateValue to get the basename of the file; currently that CalculateValue would return the first (not necessarily matching) filename and/or an error.

It looks like you were close on the CalculateValue, but are using it on the entire set of rasters instead of the single raster you are working with. If you want just the filename (sans extension) based on the input raster, you'd need to get it for the matching raster, not for the entire set of rasters in your folder.


import os
def stripextension(fname):
    return os.path.splitext(os.path.basename(fname))[0]

Try passing in the parameter %name% to this function, e.g. stripextension(%name%)

  • You understand it right , I'll try to the so ;) I may change the approach, I have new Ideas(zonal statistics instead of zonal statistics as table and direct python scripting instead of the model builder use) I will try also to fetch data directly in some attributes table, I just don't now yet how to do it... I will inform you as soon as a get some satisfying results.
    – Nour
    Commented May 21, 2019 at 21:18
  • Great, if this helped and answered your question please mark as accepted.
    – SMiller
    Commented May 21, 2019 at 21:25
  • It worked! I do not have errors, the compilation lasts about an hour, but I think however that the output is overwritten again.
    – Nour
    Commented May 22, 2019 at 9:51
  • It takes an eternity to compile, it's an infinite loop that overwrites the output again and again. Seems like "Iterate rasters" doesn't iterate as we want
    – Nour
    Commented May 22, 2019 at 11:17
  • Add %name% to your input raster line, right now you are using the same input raster for each output.
    – SMiller
    Commented May 22, 2019 at 11:42

I tried to follow the advice above, my model now looks like this : enter image description here

The calculate value content: (thanks smiller) enter image description here

The zonal statistics as table content: enter image description here

I don't have errors anymore, my initial question has been then solved!

  • You need to put something else, like %name% on the input raster line.
    – SMiller
    Commented May 22, 2019 at 11:41
  • the raster input line is set by default after linking the "iterate rasters" to the "zonal statistics as table"
    – Nour
    Commented May 22, 2019 at 12:05
  • Have you looked through this overview of using Iteration in Model Builder? Your Zonal Statistics should be using the output of whatever the current iteration of the raster is, not a specific raster every time. desktop.arcgis.com/en/arcmap/10.3/tools/modelbuilder-toolbox/…
    – SMiller
    Commented May 22, 2019 at 14:53
  • If the original answer solved your initial question please mark it as accepted. If a new question is needed, please post.
    – SMiller
    Commented May 22, 2019 at 14:54
  • 1
    It's iterating and working very well now =) I found out that I had only one tiff with "pyramids" in the beginning ^^" I corrected this thoughtlessness, and now I have my tables!
    – Nour
    Commented May 23, 2019 at 14:57

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.