Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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 ...
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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/)); } ));
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now