Open InDesign files from Subfolders using a variable
Hi all,
I have a script that opens any InDesign documents that have "0050" in the name ( Thanks to Kasyan Servetsky for the original
).
My problem is that the larger script it will be incorporated into has a variable called "pgNum" that controls which page number needs to be opened (not always page 50) so I need to replace the "0050" with the "pgNum" variable.
I've spent quite a while chopping and changing, then going back to the original but cannot find a way to do it, if anyone could help that would be fantastic
.
Many Thanks, Bren
var pgNum = 0060
var files;
var folder = Folder.selectDialog("Select a folder with InDesign documents");
if (folder != null) {
files = GetFiles(folder);
if (files.length > 0) {
// turn off warnings: missing fonts, links, etc.
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
for (i = 0; i < files.length; i++) {
app.open(files);
}
// turn on warnings
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
}
else {
alert("Found no match");
}
}
function GetFiles(theFolder) {
var files = [],
fileList = theFolder.getFiles(),
i, file;
for (i = 0; i < fileList.length; i++) {
file = fileList;
if (file instanceof Folder) {
files = files.concat(GetFiles(file));
}
else if (file instanceof File && file.name.match(/0050.*\.indd$/i)) { // ******** NEED TO CHANGE "0050" TO THE VARIABLE pgNum ********
files.push(file);
}
}
return files;
}
