Open file on Windows vs. Linux in ImageJ Macro

Hello everbody!

I have a line in my macro which works fine on OSX and Linux, but on Windows fails (Fiji):

inputDir    = getDirectory("Choose input directory");
inputFiles  = getFileList(inputDir);
for (i=0; i < inputFiles.length; i++) 
{
   run("Bio-Formats Importer", "open=" + inputDir+inputFiles[i] + " autoscale color_mode=Default rois_import=[ROI manager] view=[Standard ImageJ] stack_order=Default");
}

This fails with the following error:

(But only on Windows)

Am I using the Bioformats plugin wrongly on Windows?

Best wishes,
Stephan

Usually this is a file separator issue.
Try to use:

"open=" + inputDir + File.separator + inputFiles[i]
1 Like

Will try. Thanks for the swift response. Sent it to my colleague and will keep you posted. Maybe I need to install a VM to test also on Windows. Didn’t expect that it might be a different behaviour, but I guess the File.separator would be necessary in any case / OS, correct? It seems on my OSX it retains the file separator from the user-input directory.

The file separator issue is usually the main source when I encounter problems between OS.
But I have to say there are not many issues. So I don’t test my code on a windows machine at all.

Bigger problems are Fiji related settings, which I now set explicitly as well in my scripts.

1 Like

Dear Stephan,

You are missing square brackets after the open argument in your Bio-formats line and it breaks possibly due to spaces or weird characters.

Should be like this:

run("Bio-Formats Importer", "open=[" + inputDir+inputFiles[i] + "] autoscale color_mode=Default rois_import=[ROI manager] view=[Standard ImageJ] stack_order=Default");

If there is a space somewhere in the path, Bio-formats is to assume they are different arguments.

Try it out and let me know how it goes.

Cheers,
Nuno

edit: some wording and corrected the line of code

1 Like

Thanks. I was reading a very old thread which suggested this for another Plugin (Not Bio-Formats). I thought this would be not correct and discarded it prematurely. Thanks.