I need a little help here. I want a script that converts all the AI files in all the subfolders into PDFs and puts them in a single folder at the root and I want it to skip any folders named "Resources". I found a script that mostly does what I need it to do and I have modified it further to suit our exact needs. I'm struggling with 2 parts of it though. Specifically lines 33 and 80 are my issues now.
#target illustrator
main();
//
function main() {
var topLevel = Folder.selectDialog( 'Select the top level folder to start converting AI files to PDFX files' );
var proofFolder = new Folder( topLevel + '/Proofs2/');
proofFolder.create();
if ( topLevel != null ) {
processDocs( recursiveFolders( topLevel, /\.ai$/i ), getPDFOptions() );
};
};
//
function processDocs( aiFiles, opts ) {
var i, baseName, doc, saveFile;
for ( i = 0; i < aiFiles.length; i++ ) {
doc = app.open( aiFiles[i] );
baseName = decodeURI( doc.name.match( /(.*)\.[^\.]+$/ )[1] );
//This is line 33// saveFile = File( proofFolder.path + baseName + '.pdf' );
doc.saveAs( saveFile, opts );
doc.close( SaveOptions.DONOTSAVECHANGES );
};
};
//
function getPDFOptions() {
var pdfSaveOpts = new PDFSaveOptions();
pdfSaveOpts.acrobatLayers = true;
pdfSaveOpts.colorBars = false;
pdfSaveOpts.colorCompression = CompressionQuality.AUTOMATICJPEGHIGH;
pdfSaveOpts.compressArt = true;
pdfSaveOpts.embedICCProfile = true;
pdfSaveOpts.enablePlainText = true;
pdfSaveOpts.generateThumbnails = true;
pdfSaveOpts.optimization = true;
pdfSaveOpts.pageInformation = true;
pdfSaveOpts.preserveEditability = true;
pdfSaveOpts.pDFXStandard = PDFXStandard.PDFX1A2001;
pdfSaveOpts.viewAfterSaving = false;
return pdfSaveOpts;
};
//
function recursiveFolders( fold, exp ) {
var fileList = Array(); // Our matching files…
getFiles( fold, exp, fileList );
return fileList;
};
//
function getFiles( fold, exp, array ) {
//This is line 80// if (Folder.name !== /\Resources$/){
var i, temp;
temp = Folder( fold ).getFiles(); // All files and folders…
for ( i = 0; i < temp.length; i++ ) {
if ( temp[i] instanceof File && RegExp( exp ).test( temp[i].fsName ) ){
array.push( temp[i] );
};
if ( temp[i] instanceof Folder ) {
getFiles( temp[i].fsName, exp, array );
};
};
return array;
};
};