getFiles returns an iterator, not an array
DriveApp.getFiles() and folder.getFiles() hand back a FileIterator — an object with two methods: hasNext() returns true while items remain, and next() advances the cursor and returns the current File. There is no length property, no index access, no forEach. The first time I hit this, I tried results = folder.getFiles().length and got undefined back; the iterator just does not work that way.
The canonical pattern is a while loop: call hasNext() as the condition, call next() inside the body. Apps Script's quota logs a single Drive API call per next() invocation, so iterating 500 files costs 500 calls against your daily Drive read quota (roughly 20,000 read operations per day on a personal account, higher on Workspace). For large folders that matters.