How to loop through all illustrator files in a folder (CS6)

Posted by Julian on Super User See other posts from Super User or by Julian
Published on 2014-08-07T15:46:25Z Indexed on 2014/08/20 4:24 UTC
Read the original article Hit count: 153

Filed under:
|

I have written some JavaScript to save .ai files to two separate locations with different resolutions, one of them being cropped to a reduced size art board. (Courtesy of John Otterud / Articmill for the main part).

There are other variables in the script that I am not using at present but I want to leave the functionality there for a later date/additional layers to export/other resolutions etc.

I can't get it to loop through all files in a folder. I cannot find the script that works - or insert it at the right place. I can get as far a selecting the folder and I suppose creating an array but after that what next?

This is the create array part of the script -

// JavaScript Document
//Set up vairaibles
var destDoc, sourceDoc, sourceFolder, newLayer;

// Select the source folder.
sourceFolder = Folder.selectDialog('Select the folder with Illustrator files that you want to       mere into one', '~');
destDoc = app.documents.add();

// If a valid folder is selected
if (sourceFolder != null) {
files = new Array();

// Get all files matching the pattern
files = sourceFolder.getFiles();

I have inserted this at the beginning of the main script (probably where I am going wrong because I can select the folder but then nothing more)

#target illustrator

var docRef = app.activeDocument;

with (docRef) {

    if (layers[i].name = 'HEADER') {     
            layers[i].name = '#'+ activeDocument.name;

        save()

    }  

}


// *** Export Layers as PNG files (in multiple resolutions) ***

var subFolderName = "For_PLMA";
var subFolderTwoName = "For_VLP";
var saveInMultipleResolutions = true;
// ...
// Note: only use one character!
var exportLayersStartingWith = "%";
var exportLayersWithArtboardClippingStartingWith = "#";
// ...
var normalResolutionFileAppend = "_VLP";
var highResolutionFileAppend = "_PLMA";
// ...
var normalResolutionScale = 100;
var highResolutionScale = 200;
var veryhighResolutionScale = 300;

// *** Start of script ***
var doc = app.activeDocument;

// Make sure we have saved the document
if (doc.path != "") {

Then the rest of the export script runs on from there.

© Super User or respective owner

Related posts about batch

Related posts about adobe-illustrator