Batch code to process images in sub-folders and save tif to one folder or different folder

HI CP,

As shown in title, I am trying to process multi images in sub-folders
I want to split color and save only red channel to one folder or different folder.
Here is my code

SourceDir = getDirectory("Choose Source Directory ");

TargetDir = getDirectory("Choose Destination Directory ");

list = getFileList(SourceDir);

// Takes a directory containing sub-directories, loads them in sorted order and does an operation on them

for(i = 0; i < list.length; i++) {

 showProgress(i+1, list.length);
 subdir = SourceDir + list[i];
 Myoperation(subdir);
 close();

}

setBatchMode(true);
function Myoperation(subdir) {
run(“Image Sequence…”, “open=subdir sort”);

T = getTitle(); {

run(“Split Channels”);

selectWindow(T+" (red)");
saveAs(“tiff”, TargetDir+T);
run(“Close”);

selectWindow(T+" (blue)");
run(“Close”);

selectWindow(T+" (green)");
run(“Close”);

close("*.tif");

}
}

this code allow me to save only one image.
Is there anyone can figure out what is wrong?

Thanks.!!

I would start out with using the template provided by Fiji:
In the macro editor: Templates > ImageJ 1.x > Batch > Process Folder (IJ1 Macro)

Just copy your code into the processFile function.

Hi Schmied,

I am new user for ImageJ and sounds like I need to study.
I found macro editor from Fiji and trying. It probably takes a time.
Thanks for letting me have a opportunity to move forward.!!!

Thanks a lot !