Skip to main content
BEGINNER_X
Legend
January 25, 2013
Answered

Open all .indd files from the selected folder

  • January 25, 2013
  • 3 replies
  • 5251 views

Hi All,

I want to open all .indd files from the selected folder.

Trying script:

var myFolder = Folder.selectDialog( "Select a folder with InDesign files" );

var myFiles = [];

var myFileList = myFolder.getFiles();

for (var i = 0; i < myFileList.length; i++) {

          var myFile = myFileList;

         myFile.name.match(/\.indd$/)

          myFiles.push(myFile);

          app.open(myFiles)

          }

    

Can anyone give solution for me.

Thanks in advance

BEGINNER

This topic has been closed for replies.
Correct answer MrTIFF

var myFolder = Folder.selectDialog("Select a folder with InDesign files");

if (!myFolder)

  exit(0);

var myFileList = myFolder.getFiles();

for (var i = 0; i < myFileList.length; i++) {

  var myFile = myFileList;

          if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {

                    app.open(myFile);

          }

}

Cheers,

Stephen

3 replies

Jongware
Community Expert
Community Expert
January 25, 2013

There are a couple of conceptual errors in your script, which may be the reason you couldn't get it to work. This line

myFile.name.match(/\.indd$/)

does "nothing". It tries to find a match for the variable "myFile", but then it doesn't 'do' anything with the result -- there is no "logic" surrounding the statement. So the next line,

myFiles.push(myFile);

will always be executed. You probably meant something like

if (myFile.name.match(/\.indd$/))

   myFiles.push(myFile);

.. Javascript does what it gets told and does not do "what you mean".Next, another error is this:

app.open(myFiles)

I had to check this, but you are right: app.open can open an array of files -- I only use it to open just one file at a time. However, you placed this statement inside the main loop! So for every file in the loop, InDesign attempts to open *all* files, again and again.

With these changes, you can get your original script running properly.

By the way, note that your question has been answered before. A nice in-depth discussion is in http://forums.adobe.com/thread/791888 -- of particular interest is the entire "when is a file an InDesign file" sub-discussion.

Here is a line that works ... but I would advise you not to use it. Please try to fix your own script! Only if you understand the basic concepts, then you can advance to this:

app.open(Folder(Folder.selectDialog( "Select a folder with InDesign files")).getFiles(function(f) { return f instanceof File && !f.hidden && (f.name.match(/\.indd$/i) || f.type.match(/^IDd/)); } ));

Inspiring
October 3, 2022

hi it s possible to start with this script and adapt it for

i need to open all indd files, include into folder and subfolder, action:

 

open,update link,save,close

 

and better, export to pdf interactive before close at same place

 

thanks

Peter Kahrel
Community Expert
Community Expert
October 4, 2022

Laurence -- This is (at least) the third thread that you ask the same question in. That's confusing. Please stick to one thread/topic. The same people read these threads, there's no need to use different threads.

 

P.

Kasyan Servetsky
Legend
January 25, 2013

Here is an example of how to open all indd-files from the selected folder and its subfolders.

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;

}

Jongware
Community Expert
Community Expert
January 25, 2013

Kasyan Servetsky wrote:

Here is an example of how to open all indd-files from the selected folder and its subfolders. ...

I think I'm not going to try to do that in a single statement ...

BEGINNER_X
Legend
January 25, 2013

Respected Jongware/Kasyan/All

Thanks for your immediate response....

I created script with the help of forum:

var myFolder = Folder.selectDialog("Choose the folder")

if(myFolder.length==0)

{

    alert("No Folder Selected")

    exit(0)

    }

var myFiles = myFolder.getFiles("*.indd")

if(myFiles.length==0)

{

    alert("No InDesign files in folder")

    }

for(i=0; i<myFiles.length; i++)

{

    myFile = myFiles

    app.open(myFile)

    }

Thanks in advance

BEGINNER

MrTIFF
MrTIFFCorrect answer
Participating Frequently
January 25, 2013

var myFolder = Folder.selectDialog("Select a folder with InDesign files");

if (!myFolder)

  exit(0);

var myFileList = myFolder.getFiles();

for (var i = 0; i < myFileList.length; i++) {

  var myFile = myFileList;

          if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {

                    app.open(myFile);

          }

}

Cheers,

Stephen