Johannes Schindelin wrote
Hi,
On Wed, 17 Dec 2008, degussa wrote:
> Johannes Schindelin wrote:
> >
> > for (i = 0; i < list1.length; i++) {
> > if (File.exists(dir2 + list1[i]) &&
> > File.exists(dir3 + list1[i])) {
> > // do your thing
> > }
> > }
> >
> > I agree with you on the repeating steps, but its necessary here
> > because the files i need must have just the last four numbers in the
> > file names common to them. The folders i am using have equal numbers
> > of files (1-1000), but different file name prefix such as
> > MW24C2_1_S101_0020( folder 1), MW24C2_2_S101_0020( folder 2),
> > MW24C2_3_S101_0020( folder 3).
Okay, fair enough. Still, I would decouple that test, then (and maybe use
a higher-level language that has something like hashsets):
function inList(list, extension, last4digits) {
for (i = 0; i < list.length; i++) {
extensionIndex = indexOf(list[i], extension);
if (extensionIndex < 4)
continue;
if (substring(list[i], extensionIndex - 4, 4)
== last4digits)
return list[i];
}
return "";
}
Then I'd call this function in the loop, and only open the images when all
three of them are found:
for (i = 0; i < list1.length; i++) {
extensionIndex = indexOf(list1[i], exten1);
if (extensionIndex < 4)
continue;
last4digits = substring(list1[i], extensionIndex - 4, 4);
name2 = inList(list2, exten2, last4digits);
name3 = inList(list3, exten3, last4digits);
if (name2 == "" || name3 == "")
continue;
// only now open dir1 + list1[i], dir2 + name2
// and dir3 + name3
// then do the operations you need to do
}
It's just a hint how to structure your code better, so that you do not
miss an unadjusted number, which is a consequence of heavy copy-pasting.
Of course, you are free to let this advice go unheeded, and just fix the
number2 to number3 I pointed out in my first reply.
Ciao,
Dscho