Aim:
Once an array created its size can not be modified. Sometimes you do not know in the beginning how long a list will be. You can use the command
res = Array.concat(listOrElement1, listOrElement1);
to concatenate two arrays or to append an element to an array.
The macro below asks the user for the input folder, retrieves the names of all files in the folder and stores them in the array files
.
The aim is to create a new array images
that will contain all image-files in the folder. Fill in the code to create the empty array images
and to append file
to images
if it ends with .tif
.
Run the macro and select the folder 06
from the folder of the workshop-images.
directory = getDir("Select the input folder!");
files = getFileList(directory);
Your code starts after this line.
<create an empty array named images>
for (i = 0; i < files.length; i++) {
file = files[i];
if (endsWith(file, ".tif")) {
<append file to the array images>
}
}
Your code ends before this line.
Array.show(images);
The code below is for automatically checking the result. Please ignore it!
ok = ((images.length==3) && (files.length==5));
if (ok)
showMessage("That's right. Great, you did it!");
else
showMessage("Your result is wrong! Please check your macro and try again!");