The getFiles command returns anything that matches the mask you provide. In my example, I limited it to ""*.indd" to get only InDesign files, but — after some deliberating — I decided to add an explicit check because it may also return a Folder named "my files.indd". (Don't laugh. Of course, me personally would never name a folder something like that, but you'd be amazed.)
This 'explicit check' is right below the for..loop:
if (myList[list] instanceof Folder)
continue;
.. so the entire rest of the loop will be skipped ('continue') if the item under consideration is a folder. To make it scan for just folders, you need to make two crucial changes:
1. Change the pattern of 'getFiles' to ("*"), or omit it entirely — its default is in fact "*". This will make it pick up any and all files and folders.
2. Change the line after the for.. command to
if (myList[list] instanceof File)
continue;
so the commands below it will only be processed when 'myList[list]' is a folder.
.. Or do i need to write a loop that goes into the folder and scans until it's done?
Well … it depends on what you are planning to do. If you want to 'process' all InDesign files in a certain folder and all the ones in subfolders, possibly nested, you need a recursive routine. If you look up "Recursive" in any good dictionary, it'll read "see Recursive" — that sums it up, I guess.
A good way would be:
1. Don't use the for..loop I gave as an example, but instead define two functions: processFile and processFolder.
2. Start your script with 'processFolder'.
3. Have this function scan for all files, and call the function 'processFile' for each.
4. Then have it scan for folders, and call the function 'processFolder' for each.
You see, hopefully, that #4 is the recursive part: if there is a folder inside your main (starting) folder, the function will call itself and process the files in there. If there is a folder in that, it will call itself and process the files in that one. Et cetera ad infinitum, or until all files & folders are processed — whatever comes first.
Tip: If part of your 'processFile' involves saving the file under a new name, take care not to process these in turn! That might lead to an endless loop, not quite ad infinitum but merely ad full hard disk.