Can not apply a common operation to a complete directory with 12 bit tiff files

Hi guys, this is my first time trying to use a macro. Maybe this is a stupid question, but I was struggling on this for 3 days.

I have a file with dozens files in it. The files are 12 bit tiff format. I can not open any of the files with Fiji directly, but I can open each of them from Bio-format. The macro-record shows:

run("Bio-Formats", "open=[C:/Users/shiji/OneDrive/Desktop/Tiff bio-format/2-A.tif] autoscale color_mode=Default display_metadata rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");

I want open all the files and save them as JPEG.
If the files are not 12 bit, but 16 bit. Then they can be opened directly by Fiji. And the following Macro works.

function action(input, output, filename) {
       open(input + filename);
       saveAs("Jpeg", output + filename);
       close();
}

input = "C:/Users/shiji/OneDrive/Desktop/tiff/";
output = "C:/Users/shiji/OneDrive/Desktop/JFP/";

setBatchMode(true); 
list = getFileList(input);
for (i = 0; i < list.length; i++)
        action(input, output, list[i]);
setBatchMode(false);

When I tried to operate the file with 12 bit files with the following macro. it did not work.

function action(input, output, filename) {
       run("Bio-Formats", "open=[input + filename] autoscale color_mode=Default display_metadata rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
       saveAs("Jpeg", output + filename);
       close();
}

input = "C:/Users/shiji/OneDrive/Desktop/tiff/";
output = "C:/Users/shiji/OneDrive/Desktop/JFP/";


setBatchMode(true); 
list = getFileList(input);
for (i = 0; i < list.length; i++)
        action(input, output, list[i]);
setBatchMode(false);

What’s wrong with it?

Hi @shijingff, if you use the Bio-Formats exporter to do the conversion does that work any better?

 function action(input, output, filename) {
       run("Bio-Formats", "open=[input + filename] autoscale color_mode=Default display_metadata rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
       run("Bio-Formats Exporter", "save=[output+filename.jpg]");
       close();
}

Thanks dgault.
The result is the same:
“the specified file (input + filename) does not exist”

A friend just helped me out by the following method. Although I don’t know how it works.

function action(input, output, filename) {
	 inputfile = input+filename;
       run("Bio-Formats", "open=["+ inputfile +"] autoscale color_mode=Default display_metadata rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
       saveAs("Jpeg", output + filename);
       close();
}

input = "C:/Users/shiji/OneDrive/Desktop/Tiff bio-format/";
output = "C:/Users/shiji/OneDrive/Desktop/JFP/";


setBatchMode(true); 
list = getFileList(input);
for (i = 0; i < list.length; i++)
        action(input, output, list[i]);
setBatchMode(false);