Process pictures in all subfolders

Hello evrybody =)
I am trying to write a macro which should process pictures in the last subfolder and have some problems. The microscope saves the images as following:
FolderA --> Sample1 --> stack --> frame_t_0.ets
FolderA --> Sample2 --> stack --> frame_t_0.ets
This means, the “FolderA” and “Sample1” folders will not contain any images, only the last folder (“stack”) will contain one file ("frame_t_0.ets). I would like ImageJ to process the frame_t_0.ets file and name it f.ex. Sample2_blue.
My macro starts like this:

input = getDirectory(“Input directory”);
output = “output_”+input;

suffix = “.ets”;

processFolder(input);

function processFolder(input) {
list = getFileList(input);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + list[i]))
processFolder("" + input + list[i]);

    if(endsWith(list[i], suffix))   
	{
path = input+list[i];
setBatchMode(true);
title = File.nameWithoutExtension;

run

if I try to run it, it just doesn’t do anything…I hope somebody can help me!
(additional info: on the mac of a friend this macro works, just not on my windows pc)

hole macro:
input = getDirectory(“Input directory”);
output = “output_”+input;

suffix = “.ets”;

processFolder(input);

function processFolder(input) {
list = getFileList(input);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + list[i]))
processFolder("" + input + list[i]);

    if(endsWith(list[i], suffix))   
	{
path = input+list[i];
setBatchMode(true);
title = File.nameWithoutExtension;

run(“Bio-Formats”, “open=[path] autoscale color_mode=Custom open_all_series split_channels view=Hyperstack stack_order=XYCZT use_virtual_stack series_0_channel_0_red=0 series_0_channel_0_blue=255 series_0_channel_1_red=255 series_0_channel_1_blue=0 series_1_channel_0_red=0 series_1_channel_0_blue=255 series_1_channel_1_red=255 series_1_channel_1_blue=0”);
selectWindow(“frame_t_0.ets - TRITC, DAPI - C=1”);
run(“Z Project…”, “start=1 stop=20 projection=[Max Intensity]”);
run(“Blue”);
saveAs(“JPEG”, input+“blue.jpg”);
selectWindow(“frame_t_0.ets - TRITC, DAPI - C=1”);
close();
selectWindow(“frame_t_0.ets - TRITC, DAPI - C=0”);
run(“Z Project…”, “start=1 stop=20 projection=[Max Intensity]”);
run(“Red”);
saveAs(“JPEG”, input+“red.jpg”);
selectWindow(“frame_t_0.ets - TRITC, DAPI - C=0”);
close();
selectWindow(“MAX_frame_t_0.ets - TRITC, DAPI - C=0”);

run(“Merge Channels…”, “c3=[MAX_frame_t_0.ets - TRITC, DAPI - C=1] c1=[MAX_frame_t_0.ets - TRITC, DAPI - C=0]”);
saveAs(“JPEG”, input+“merged.jpd”);
run(“Close”);
setBatchMode(false);
selectImage(nImages);
close();
}

Hi,

I guess it has something to do with the file separator.
I think you are using a old version of the batch processing template.
You could try the current version of it:

/*
 * Macro template to process multiple images in a folder
 */

#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix

// See also Process_Folder.py for a version of this code
// in the Python scripting language.

processFolder(input);

// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
	list = getFileList(input);
	list = Array.sort(list);
	for (i = 0; i < list.length; i++) {
		if(File.isDirectory(input + File.separator + list[i]))
			processFolder(input + File.separator + list[i]);
		if(endsWith(list[i], suffix))
			processFile(input, output, list[i]);
	}
}

function processFile(input, output, file) {
	// Do the processing here by adding your own code.
	// Leave the print statements until things work, then remove them.
	print("Processing: " + input + File.separator + file);
	print("Saving to: " + output);
}

Thanks a lot for your suggestion! I included it now in my Macro:

input = getDirectory(“Input directory”);
output = “output_”+input;

suffix = “.ets”;

function processFolder(input) {
list = getFileList(input);
list = Array.sort(list);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + File.separator + list[i]))
processFolder(input + File.separator + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);
}
}

function processFile(input, output, file) {
// Do the processing here by adding your own code.
// Leave the print statements until things work, then remove them.
print("Processing: " + input + File.separator + file);
print("Saving to: " + output);
}
title = File.nameWithoutExtension;
run

But if I try to run it, I get the following error message:

The specified file (path) does not exist.

You need to put the code that should run over the files within the processFile() function.
Thus place it within the curly braces of the processFile() function.

Also your output variable makes no sense. I would suggest you make a new output directory.

Cheers,
Christopher