Howdy,
I want to write a function that does a thing to everything in a directory, and recurses over subdirectories if I tell it too, it looks like this:
Folder.prototype.crawl = function(action, mask, recursion) { // does (action) on every file matching (mask), if (recursion) is true then subdirectories are crawl()-ed as well var workingList = this.getFiles(mask); for (i = 0; i < workingList.length; i++) { if (typeof workingList[i].open == "undefined") { // its a directory if (recursion) { workingList[i].crawl(action, mask, recursion); } } else { action(workingList[i]); } } } var rootDirectory = Folder.selectDialog(); rootDirectory.crawl(alert, "", true);
It doesn't behave as it should, and its hard to pin down exactly what's not working. Most of the time it will recurse down directories until it finds the first folder with more than one file inside, then iterate over all those files, then quit. What looks wrong here? Is there a better way to tell if a a getFiles() result is a directory or not?