Login  Register

Recursively lists

Posted by Johannes Breu on Sep 18, 2008; 4:52pm
URL: http://imagej.273.s1.nabble.com/Recursively-lists-tp3685716.html

Hello,

version A works.

*Version A*
// Recursively lists the files in a user-specified directory
// With ImageJ 1.37i or later, open files on the list by
// double clicking on them. A preview of 1.37i is available at
//   http://rsb.info.nih.gov/ij/ij.jar

  requires("1.32f");
  dir = getDirectory("Choose a Directory ");
  count = 1;
  listFiles(dir);

  function listFiles(dir) {
      list = getFileList(dir);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              listFiles(""+dir+list[i]);
          else
              print((count++) + ": " + dir + list[i]);
      }
  }

If I address dir to another variable it doesn´t work. Why?

*Version B*
// Recursively lists the files in a user-specified directory
// With ImageJ 1.37i or later, open files on the list by
// double clicking on them. A preview of 1.37i is available at
//   http://rsb.info.nih.gov/ij/ij.jar

  requires("1.32f");
  dir = getDirectory("Choose a Directory ");

  count = 1;
  listFiles(dir);

  function listFiles(dir) {
      list = getFileList(dir);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              listFiles(""+dir+list[i]);
          else
              *m=dir;*
              print((count++) + ": " *+ m* + list[i]);
      }
  }

Actually I would like to have the possibility to treat *dir or m* as an
variable becaus I wish to extract a substring out of *dir*.


Thanks