Login  Register

Re: Opening images from Different folders for stacking

Posted by dscho on Dec 17, 2008; 1:17pm
URL: http://imagej.273.s1.nabble.com/Opening-images-from-Different-folders-for-stacking-tp3694155p3694156.html

Hi,

On Mon, 15 Dec 2008, degussa wrote:

> for (k=0; k<list3.length; k++) {
>
>          index4 = indexOf(list3[k], exten3);
>          index5 = index6-4;
> //         number3 = substring(list3[j], index5, index6);
>
>     if(number1 == number2) {

This wants to be number3 instead of number2.

BTW your code could use some serious refactoring: it seems that you do the
same step in all three loops; just put that code into a function, and you
macro gets much more readable.

Also, once you found the match ("if (number1 == number2)") you might want
to "break;" in order to avoid running through the loops unnecessarily.

However, you might want to avoid the inner loops altogether: apparently
you want to know if the other two directories have a file of the same
name?  You can do that much quicker by saying

        for (i = 0; i < list1.length; i++) {
                if (File.exists(dir2 + list1[i]) &&
                                File.exists(dir3 + list1[i])) {
                        // do your thing
                }
        }

Hth,
Dscho