Copy link to clipboard
Copied
I am having an odd issue with the getFiles() function: It is returning the list of folders I want, but won't let me interact with them as an array.
Here is my code:
const basePath = "C:/Users/O146962/OneDrive - Kaiser Permanente/Documents/GitHub/kp_pd_xml_automation";
const mainFolder = basePath + "/Indesign Automation POC";
const templateFolder = Folder(mainFolder + "/Templates");
const rgnTemplateFolders = templateFolder.getFiles("*_inddTemplates");
alert(rgnTemplateFolders.length());
Note that the const templateFolder is declared as a Folder object.
If I set the alert to
alert(rgnTemplateFolders);
The script produces the following:
If I set the alert to:
alert(rgnTemplateFolders[1]);
I get:
BUT, if I set the alert to:
alert(rgnTemplateFolders.length());
I get:
I have been hunting through these forums and found the following posts, but none of them seem to specifically deal with this issue.
What am I missing here?
Well now I feel a bit stupid. A colleague pointed out that I needed to use
alert(rgnTemplateFolders.length);
since length is a property and not a method. 🤦
InDesign scripting is based on ECMAScript 3. foreach didn't exist back then...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Well now I feel a bit stupid. A colleague pointed out that I needed to use
alert(rgnTemplateFolders.length);
since length is a property and not a method. 🤦
Copy link to clipboard
Copied
That error is understandable as you are at the same time learning Extendscript's XML, where almost everything – including "length()" – is a function rather than a property.
Copy link to clipboard
Copied
Seems to me that all's well, you get what you asked for. The list of folders shown by
alert(rgnTemplateFolders);
is an array. And
alert(rgnTemplateFolders[1]);
shows the first element in the array.
When you run this:
alert(rgnTemplateFolders).join('\r');
the files are printed as a list, as you'd expect, using the array function ,join().
alert(rgnTemplateFolders.length());
returns an error because .length is a property, not a function, as your error message tells you.
Why do you think that alert(rgnTemplateFolders); does not return an array?
(In the meantime Ben Ross figured it out.)
Copy link to clipboard
Copied
Thanks @Peter Kahrel ! Since the results of getFiles() IS an array, why does using array.forEach() say that forEach is not a function?
Copy link to clipboard
Copied
InDesign scripting is based on ECMAScript 3. foreach didn't exist back then...
Copy link to clipboard
Copied