Saving stack to a macro-created folder, issue with ImageJ 1.53h

Hi all,

I’ve just updated ImageJ to 1.53h and my script is not working anymore, in particular I have something like this:

dir = getDirectory("Choose a Directory"); 
WDir = dir + "/Watershed/"; // create folders inside the directory for saving later the stacks

// process images

run("Image Sequence... ", "format=TIFF save=[WDir]"); // to save the output in that specific folder

now it’s not working, displaying the following:

File saving error (IOException):

“WDir\newmacro-Thresholded0000.tif (Cannot find specified path)”
WDir/newmacro-Thresholded0000.tif in line 33:

anyone found this error as well?

Dear @Leeviats,

my guess is that the problem are your file separators.

getDirectory(x) gives you already a file separator at the end of the path. If you then add another one using the forward slash “/” that might not work properly.

To create a directory I would use the following code:

dir = getDirectory("Choose a Directory"); 

outputDirName = dir + "MyDirName";
outputDirPath = outputDirName + File.separator;


//if you want to save something use the path

run("Image Sequence... ", "format=TIFF save=["+outputDirPath+"]");

The difference is that you create a directory just by using really its name but you need a file separator in the path to be able to save files in that directory.
Finally, you added your "WDir " as fixed text which might create problems at some point. In case of using variables it is recommended to combine them with fixed text outside quotation marks using a + sign.


Hi Lorenzo,
Are you sure you dont have a mistake in your command here, WDir is not passed as a variable here, but as a string (so basically asking to save in a directory name WDir.

run("Image Sequence... ", "format=TIFF save=[WDir]"); // to save the output in that specific folder

What about

run("Image Sequence... ", "format=TIFF save=[" + WDir + "]"); // to save the output in that specific folder

Or I think you can also use preceed the variable name with & like

run("Image Sequence... ", "format=TIFF save=[&WDir]"); // to save the output in that specific folder
1 Like

Thank you both, that was helpful! I’m still trying to get a firm understanding of how ImageJ language works :slight_smile:

Kind regards,


This covers most of the information about the macro-language :wink:
Macro Language (