Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Open all .indd files from the selected folder

Enthusiast ,
Jan 24, 2013 Jan 24, 2013

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

TOPICS
Scripting
5.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jan 24, 2013 Jan 24, 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

Translate
Engaged ,
Jan 24, 2013 Jan 24, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 24, 2013 Jan 24, 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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2013 Jan 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 ...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 25, 2013 Jan 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2013 Jan 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/)); } ));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 03, 2022 Oct 03, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2022 Oct 04, 2022
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines