How to automate direcrory selection

Hi all,

I am trying to create a pipeline that will automatically process multiple images. The problem is that each time I start the process and load a new image, Fiji asking me to enter the input and output directories. Is there a way to change the following macro such that the program doesn’t prompt me to “choose the directory”?

I’d be very thankful to nay suggestions.


//select input directory for pipeline 

dir1 = getDirectory("C:\Boss\Platelet-distances\2_Input");
list = getFileList( dir1 );
for ( i=0; i<list.length; i++ ) {
    open( dir1 + list[i] );


dir2 = getDirectory("C:\Boss\Platelet-distances\3_Output"); 
for (i=0;i<nImages;i++) { 
        title = getTitle; 

        saveAs("tiff", dir2+title); 
run("Close All");

If you do not want to select a directory simply write

dir1 = "C:\\Boss\\Platelet-distances\\2_Input";

instead of

dir1 = getDirectory("C:\Boss\Platelet-distances\2_Input");

you can find information about the getDirectory function:

Displays a “choose directory” dialog and returns the selected directory, or returns the path to a specified directory, such as “plugins”, “home”, etc. …

1 Like

hmm, I tried removing "getDirectory (……) and it didn’t work…

I work under windows
@phaub 's proposal works well.

dir1 = "C:\\Boss\\Platelet-distances\\2_Input";

list = getFileList( dir1 );
for ( i=0; i<list.length; i++ ) {
    open( dir1 + list[i] );

with double anti slach

dir1 = "C:/Boss/Platelet-distances/2_Input";

list = getFileList( dir1 );
for ( i=0; i<list.length; i++ ) {
    open( dir1 + list[i] );

I did try and now I am getting this error massage

Hi @varlamov!

I think you are missing the double slash at the end of dir1

dir1 = "C:\\Oleg\\Platelet-distances\\2_Input\\"

so that when you concatenate this directory path with the filename, you actually get a correct complete path to the file.


You are right!
And it was I who introduced the error in my answer!!!

1 Like

Hi Nico, you are a genius! The pipeline works very well now. Thank you very much.

I have an additional question, which sounds like an easy task for a programmer.

Is it possible to load a new image from a parent directory after each run? Essentially, I envision the following steps:

  1. Move file-1 from the parent directory to input directory.
  2. Run image analysis macro.
  3. Clear input directory.
  4. Move file-2 from parent directory to input directory.
  5. Repeat until parental directory in empty.

This should create high-throughput automation.

Have a look at the File Functions in the macro built-in functions:

File.copy(path1, path2);

I just wonder why you would need these operations that you describe in the first place?
Why not work on the parental directory directly? From you description the moving serves no direct purpose.

1 Like