Loop for automation of image processing

Hello all,

I am using Imagej but I must say I am not good at all in programming.
I want to implement a for loop that will read the images in my directory, subtract their background and merge them, convert them into a different type and save them. There are two types of images, those obtained with DAPI and those obtained with Texas Red. I have recorded the macros so with the exception of color adjustment it performs all the tasks. However, it is applicable only for a pair of images and then I just adjust it manually. I would like to scale it up and automate it. Please. if you have any ideas let me know. This very basic macro is found below (the path was too long so for reading facility I just substituted it with ‘destination path’).

open(“destination path/DAPI_02.tif”);
run(“Subtract Background…”, “rolling=25”);
open(“destination path/Texas Red_02.tif”);
run(“Subtract Background…”, “rolling=25”);
run(“Merge Channels…”, “c1=[Texas Red_02.tif] c3=DAPI_02.tif create”);
run(“Color Balance…”);
run(“RGB Color”);
run(“Scale Bar…”, “width=100 height=5 font=18 color=White background=None location=[Lower Right] bold”);
saveAs(“Tiff”, “destination path/image2.tif”);

Using the search terms processFolder, processFile, File.isDirectory and File.getFileList will get you a load of articles in this forum.
And for the definitions and syntax, look at

Build your destination path using a variable, this shortens the code and shows the values in the debug window.

Thank you, I will check your suggestions and the provided link.