Skip to main content
Inspiring
May 15, 2024
Answered

Open all indd files from selected folder and its sub-folders

  • May 15, 2024
  • 1 reply
  • 456 views

Hi all! 🙂

I have found this script written by @Kasyan Servetsky on an old post, and it's exactly what I need. However, somehow it's not working for me. When I select the folder, I get this message "Found no InDesign documents" even if there are indd files in the folder and its sub-folders. Could anyone have a look please? Thanks in advance!

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 InDesign documents");

    }

}

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(/\.indd$/i)) {

            files.push(file);

        }

    }

    return files;

}

 

This topic has been closed for replies.
Correct answer Kasyan Servetsky

Sorry! Here's a mistake: 

file = fileList[0];
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 InDesign documents");
	}
}
function GetFiles(theFolder) {
	var files = [],
	fileList = theFolder.getFiles(),
	i, file;
	for (i = 0; i < fileList.length; i++) {
		file = fileList[0];
		if (file instanceof Folder) {
			files = files.concat(GetFiles(file));
		}
		else if (file instanceof File && file.name.match(/\.indd$/i)) {
			files.push(file);
		}
	}
	return files;
}

Also, check out my batch processor script.

— Kas

1 reply

Kasyan Servetsky
Kasyan ServetskyCorrect answer
Legend
May 17, 2024

Sorry! Here's a mistake: 

file = fileList[0];
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 InDesign documents");
	}
}
function GetFiles(theFolder) {
	var files = [],
	fileList = theFolder.getFiles(),
	i, file;
	for (i = 0; i < fileList.length; i++) {
		file = fileList[0];
		if (file instanceof Folder) {
			files = files.concat(GetFiles(file));
		}
		else if (file instanceof File && file.name.match(/\.indd$/i)) {
			files.push(file);
		}
	}
	return files;
}

Also, check out my batch processor script.

— Kas