If the code you posted works correctly for the documents in the selected folder, then the code below should work correctly for all documents in the selected folder and subfolders. Array.prototype.unique = function unique() { var i, a = {}, r = [], n = this.length; for (i = 0; i < n; ++i) { a[this] = 1; } for (i in a) { r.push(i); } return r; } if (app.documents.length == 0) { fontReporter(); } else { alert("Please close all documents!", "Font Report Creator"); } function fontReporter() { app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; // write report to file var writeReport = function writeReport(myData, myFile) { myFile.open('w'); myFile.encoding = 'UTF-8'; for (var d = 0; d < myData.length; d++) { myFile.write(myData ); } myFile.close(); } // collect info from document var createFontReport = function createFontReport(myDoc) { var myDocFonts = myDoc.fonts; var myDocName = myDoc.name; myFonts.push("//// Font report for file: [ " + myDocName + " ] ////\r\r"); for(var f = 0; f < myDocFonts.length; f++) { var myString = myDocFonts .fontFamily + "\t" + myDocFonts .fontStyleName + "\t" + myDocFonts .location + "\r"; myFonts.push(myString); myFontsAll.push(myString); } //myFonts.sort(); myFonts.push("\r//// Fonts used count: " + f + " ////\r\r\r"); } /** * Calls the callback function for each descendant file of the specified folder. * The callback should accept a single argument that is a File object. * * @param {Folder} folder The folder to search in. * @param {Function} callback The function to call for each file. */ var forEachDescendantFile = function forEachDescendantFile(folder, callback) { var aChildren = folder.getFiles(); for (var i = 0; i < aChildren.length; i++) { var child = aChildren; if (child instanceof File) { callback(child); } else if (child instanceof Folder) { this.forEachDescendantFile(child, callback); } else { throw new Error("The object at \"" + child.fullName + "\" is a child of a folder and yet is not a file or folder."); } } } /** * Returns true if the name of the given file ends in the given extension. Case insensitive. * * @param {File} iFile * @param {String} sExtension The extension to match, not including the dot. Case insensitive. * @return {boolean} */ var matchExtension = function matchExtension(iFile, sExtension) { sExtension = "." + sExtension.toLowerCase(); var displayName = iFile.displayName.toLowerCase(); if (displayName.length < sExtension.length) { return false; } return displayName.slice(-sExtension.length) === sExtension; } var openIfDocument = function openIfDocument(oFile) { if (matchExtension(oFile, "indd")) { var document = app.open(oFile, false); try { if (document.saved == true) { createFontReport(document); } } finally { document.close(SaveOptions.no); } } } var myFonts = []; var myFontsAll = []; // open/report/close var myFolder = Folder.selectDialog("Please select a folder containing the InDesign files."); if (myFolder == null) { alert("No folder selected!", "Font Report Creator"); exit(); } forEachDescendantFile(myFolder, openIfDocument); var myReportFile = File(myFolder + "/" + "Separate document report - Font Report.txt"); writeReport(myFonts, myReportFile); // complete report myFontsAll = myFontsAll.unique(); myFontsAll.sort(); myFontsAll.unshift("//// Font report for folder: [ " + myFolder + " ]////\r\r"); myFontsAll.push("\r//// Fonts used count: " + (myFontsAll.length - 1) + " ////"); myReportFile = File(myFolder + "/All [INDD] Documents Font Report.txt"); writeReport(myFontsAll, myReportFile); app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL; alert("Font reports created!", "Font Report Creator"); } The code you posted calls createFontReport() for each document in the selected folder. I replaced that with forEachDescendantFile(myFolder, openIfDocument);, which should call createFontReport() for each decendant document in the selected folder.
... View more