Login  Register

Re: Recursively lists

Posted by jmutterer on Sep 18, 2008; 6:38pm
URL: http://imagej.273.s1.nabble.com/Recursively-lists-tp3685716p3685717.html

Johannes,
you should include all the else statement between curly braces :

 if (endsWith(list[i], "/"))
           listFiles(""+dir+list[i]);
 else {
             m=dir;
             print((count++) + ": " + m + list[i]);
  }


the braces can be omitted if the statement carries only one instruction.

Jerome

On Thu, Sep 18, 2008 at 6:52 PM, Johannes Breu <[hidden email]> wrote:

> 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
>