adobe - Javascript code to open several files in subdirectories -
i'm new programmer, please bear me. i'm attempting pretty advanced, enjoy challenge. :~) i'm using adobe's estk (extendscript toolkit) write complex script indesign cs6. i've gone through of tutorials , have learned quite bit, have run wall now.
i need script detect whether folder meets criteria, , if does, delve folder, count of subfolders, , open each of .indd files in each of subfolders, in turn, performing tasks on each one. have started script today , i've got far:
var getdatadialog = app.dialogs.add({name:"job info"}); with(getdatadialog){ // add dialog column. with(dialogcolumns.add()){ // create order number text edit box. var ordernumtexteditbox = texteditboxes.add({minwidth:80}); } } // show dialog box. var dialogresult = getdatadialog.show(); if(dialogresult == true){ // order number , put in variable "ordernum". var ordernum = ordernumtexteditbox.editcontents; // first 3 numbers of order number , put in "orderprefix". var orderprefix = ordernum.substr(0,3); // remove dialog box memory. getdatadialog.destroy(); // store folder prefix "folderprefix". var folderprefix = "/g/ artdept/jobs/" + orderprefix + "000-" + orderprefix + "999/" // open document order number. var mydoc = app.open(file(folderprefix + ordernum + " folder/" + ordernum + ".indd"), true); } else{ getdatadialog.destroy(); }
so, if order number entered "405042", in "405000-405999" folder, packaged folder called "405042 folder", open .indd file inside that. trouble is, have several packages within folder. example, might have:
405000-405999/405007/405007_n10/405007_n10.indd 405000-405999/405007/405007_c12/405007_c12.indd 405000-405999/405007/405007_orange/405007_orange.indd
i want script open each of files, in turn, , perform tasks on them. i'm it's possible, need know how code it. please let me know if need more information , i'll gladly provide it. thank you!
if understand problem correctly, there 2 parts:
part 1: find folder meeting criteria. (looks you've got covered.)
part 2: each indesign document descendant of folder, open , processing it.
in sample below, i've labeled should add code finds top folder , code manipulates each document. if run sample as-is, use script's parent folder top folder, , each descendant document log name.
// todo: (part 1) put code here determines top folder. var topfolder = (new file($.filename)).parent; // change me. script's folder. foreachdescendantfile(topfolder, dostuffifdocument); // don't change line. /** * stuff document. */ function dostuff(document) { // todo: (part 2) put code here manipulate document. $.writeln("found document " + document.name); } /** * opens given file if ends in ".indd". calls dostuff(). * * @param {file} ofile */ function dostuffifdocument(ofile) { if (matchextension(ofile, "indd")) { var document = app.open(ofile); try { dostuff(document); } { document.close(saveoptions.yes); } } } /** * calls callback function each descendant file of specified folder. * callback should accept single argument file object. * * @param {folder} folder folder search in. * @param {function} callback function call each file. */ function foreachdescendantfile(folder, callback) { var achildren = folder.getfiles(); (var = 0; < achildren.length; i++) { var child = achildren[i]; if (child instanceof file) { callback(child); } else if (child instanceof folder) { this.foreachdescendantfile(child, callback); } else { throw new error("the object @ \"" + child.fullname + "\" child of folder , yet not file or folder."); } } } /** * returns true if name of given file ends in given extension. case insensitive. * * @param {file} ifile * @param {string} sextension extension match, not including dot. case insensitive. * @return {boolean} */ function matchextension(ifile, sextension) { sextension = "." + sextension.tolowercase(); var displayname = ifile.displayname.tolowercase(); if (displayname.length < sextension.length) { return false; } return displayname.slice(-sextension.length) === sextension; }
Comments
Post a Comment