Login  Register

Batch processes through plugins

Posted by jswalker on Aug 05, 2015; 7:34pm
URL: http://imagej.273.s1.nabble.com/Batch-processes-through-plugins-tp5013914.html

Hi all,

I'm trying to do a couple operations on many files in a folder, but these operations must be done through plugins (eg BioFormats, or ND2Reader).

The recorder spits this out:

run("Bio-Formats Importer", "open=[C:\\file\\path\\file.tif] insertoptionshere");

How do I make this perform the same action on all files in a list? I understand how to do this when I'm not doing it through a plugin -- my question is specifically about doing this within the plugin syntax shown above.

I'm working with the following script:

   requires("1.33s"); 
   dir = getDirectory("Choose a Directory: ");
   setBatchMode(true);
   count = 0;
   countFiles(dir);
   n = 0;
   processFiles(dir);
   //print(count+" files processed");
   
   function countFiles(dir) {
      list = getFileList(dir);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              countFiles(""+dir+list[i]);
          else
              count++;
      }
  }

   function processFiles(dir) {
      list = getFileList(dir);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              processFiles(""+dir+list[i]);
          else {
             showProgress(n++, count);
             path = dir+list[i];
             processFile(path);
          }
      }
  }

  function processFile(path) {
       if (endsWith(path, ".tif")) {
           [COMMAND GOES HERE]
           close();
      }
  }

I've tried universalizing the line that the recorder spits out, but it gives me an error.

I tried looking for this in the archives but may have been using the wrong search terms -- sorry if so. Many thanks in advance!