Batch convert .ai to .eps including subfolders

New Here ,
Apr 09, 2018 Apr 09, 2018

Copy link to clipboard

Copied

I have a ton of .ai files(1000+), in folders, that I want to copy/convert to .eps files. I am trying to figure out a script but do not know enough about it to do it. Anyone know of an easy way to do this?

Thanks

Cheryl

TOPICS
Scripting

Views

2.6K

Likes

Translate

Translate

Report

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

Valorous Hero , Apr 10, 2018 Apr 10, 2018
//Some utils to retrieve files in folders and subfoldersvar api = {getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder ){var exts = aExtensions? aExtensions.join("|") : ".+" ;var pattern = new RegExp ( "\\.("+exts+")$");!aFiles && aFiles = [];var filterFunction = function(file){return pattern.test ( file.name );}if ( bRecursive && fo.name.indexOf ( ".")!=0 ){var foFiles = fo.getFiles();while (  f = foFiles.shift() ){if ( f instanceof Folder ){if (includeFolder===true) files[...

Likes

Translate

Translate
New Here ,
Apr 09, 2018 Apr 09, 2018

Copy link to clipboard

Copied

I am using CS6.

Likes

Translate

Translate

Report

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 ,
Apr 10, 2018 Apr 10, 2018

Copy link to clipboard

Copied

//Some utils to retrieve files in folders and subfolders

var api = {

getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder )

{

var exts = aExtensions? aExtensions.join("|") : ".+" ;

var pattern = new RegExp ( "\\.("+exts+")$");

!aFiles && aFiles = [];

var filterFunction = function(file)

{

return pattern.test ( file.name );

}

if ( bRecursive && fo.name.indexOf ( ".")!=0 )

{

var foFiles = fo.getFiles();

while (  f = foFiles.shift() )

{

if ( f instanceof Folder )

{

if (includeFolder===true) files[ files.length ] = f;

this.getFiles ( f, aExtensions, true, aFiles );

}

if ( f  instanceof File && pattern.test ( f.name ) && f.name!=".DS_Store" ) {

aFiles[ aFiles.length ]  = f;

}

}

return aFiles;

}

else

{

return fo.getFiles ( filterFunction );

}

},

}

//Main routine

var main = function() {

var fo = Folder.selectDialog("Please select a folder"),

files, n = 0, doc, nFile,

opts = new EPSSaveOptions();

//Settings options

// opts.… = …

//Exit if no selected folder

if ( !fo ) return;

//getting AI files

files = api.getFiles ( fo, ["ai"], true );

n = files.length;

//Exit if no files found

if ( !n ) {

alert( "No files found sorry" );

return;

}

//convert found files

while ( n-- ) {

nFile = files;

doc = app.open ( files );

doc.saveAs ( File ( nFile.parent+"/"+nFile.name.replace ( /\.ai$/, '.eps' ) ), opts );

doc.close();

}

}

//run

main();

HTH

Likes

Translate

Translate

Report

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
New Here ,
Aug 07, 2018 Aug 07, 2018

Copy link to clipboard

Copied

Loic.Aigon ,

I've read tutorial after tutorial and can't seem to wrap my head around scripting for Illustrator. I'm looking to do just the opposite of what the OP wanted to do, I need to convert folders full of EPS files back to AI. If I were to switch those references around in the script you have provided would that work? If not, I don't want to bother you any further, just hoping it would be as easy as I'm speculating it to be.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Aug 07, 2018 Aug 07, 2018

Copy link to clipboard

Copied

You will have to change the save options to be the Illustrator ones (l.47) and the save-as file object to replace the eps with ai instead of how it is now (l.70).

Likes

Translate

Translate

Report

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
New Here ,
May 31, 2020 May 31, 2020

Copy link to clipboard

Copied

sorry i wanna post a question about converting the eps to ai file , that i saw this post.can you help me for this?

Likes

Translate

Translate

Report

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
Advocate ,
May 31, 2020 May 31, 2020

Copy link to clipboard

Copied

Bonjou dr_rapide

Si tu veux faire l'inverse eps vers ai, tu remplaces la fin du script de Loïc à partir de la ligne 33

par

 

//Main routine  ligne 33
  var main = function() {
    var fo = Folder.selectDialog("Please select a folder"),
    files, n = 0, doc, nFile;
    //Settings options
    // Options pour l’enregistrement d’un document au format Illustrator.
  var opts  = new IllustratorSaveOptions();
  // opts.… = …
    //Exit if no selected folder
      if ( !fo ) return;
    //getting AI files
      files = api.getFiles ( fo, ["eps"], true );    // alert(files)
      n = files.length;
    //Exit if no files found
      if ( !n ) {
        alert( "No files found sorry" );
      return;
      }
    //convert found files
      while ( n-- ) {
        nFile = files[n];
        doc = app.open ( files[n] );
        doc.saveAs ( File ( nFile.parent+"/"+nFile.name.replace ( /\.eps$/, '.ai' ) ), opts );
        doc.close();
      }
}
//run
main();

 

restera si besoin à définir les options autres que par défaut

ligne  //opts. ... = ....

de elleere

 

 

Likes

Translate

Translate

Report

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
New Here ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

tnx a lot .

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
May 31, 2020 May 31, 2020

Copy link to clipboard

Copied

Hi Loic_Aigon,

Thanks for your answer! Would you mind explaining a line to me please?

!aFiles && aFiles =[];

 This line causes my linter to complain. Is it functionally the same as writing:

if (!aFiles) aFiles = [];

Thanks,

Mark

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
May 31, 2020 May 31, 2020

Copy link to clipboard

Copied

Yes, that's correct,. If aFiles does not declared, it goes to the second condition after && and declared aFiles as an array.

 

Best regards

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

👍

Likes

Translate

Translate

Report

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
New Here ,
Oct 27, 2020 Oct 27, 2020

Copy link to clipboard

Copied

Hi I am trying to use this script again but no on CC2021. Getting an error.error.jpg

 

Likes

Translate

Translate

Report

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
New Here ,
Oct 27, 2020 Oct 27, 2020

Copy link to clipboard

Copied

I am also going from eps to ai now.

Likes

Translate

Translate

Report

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
Advocate ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Bonjour,

Il faut inclure le début du script de Loïc placé avant

//Main routine ligne 33

 

 

Likes

Translate

Translate

Report

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
New Here ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

//Some utils to retrieve files in folders and subfolders

var api = {

getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder )

{

 

var exts = aExtensions? aExtensions.join("|") : ".+" ;

var pattern = new RegExp ( "\\.("+exts+")$");

!aFiles && aFiles = [];

var filterFunction = function(file)

{

return pattern.test ( file.name );

}

 

if ( bRecursive && fo.name.indexOf ( ".")!=0 )

{

var foFiles = fo.getFiles();

while (  f = foFiles.shift() )

{

if ( f instanceof Folder )

{

if (includeFolder===true) files[ files.length ] = f;

 

this.getFiles ( f, aExtensions, true, aFiles );

}

if ( f  instanceof File && pattern.test ( f.name ) && f.name!=".DS_Store" ) {

 

aFiles[ aFiles.length ]  = f;

}

}

 

return aFiles;

}

 

else

{

return fo.getFiles ( filterFunction );

}

},

}

 

 

//Main routine

var main = function() {

 

var fo = Folder.selectDialog("Please select a folder"),

files, n = 0, doc, nFile,

opts = new EPSSaveOptions();

 

//Settings options

// opts.… = …

 

//Exit if no selected folder

if ( !fo ) return;

 

//getting AI files

files = api.getFiles ( fo, ["ai"], true );

n = files.length;

 

//Exit if no files found

if ( !n ) {

alert( "No files found sorry" );

return;

}

 

 

//convert found files

while ( n-- ) {

nFile = files;

doc = app.open ( files );

doc.saveAs ( File ( nFile.parent+"/"+nFile.name.replace ( /\.ai$/, '.eps' ) ), opts );

doc.close();

}

}

 

 

//run

main();

 

Likes

Translate

Translate

Report

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
New Here ,
Feb 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

I am using this script to convert .ai to .eps files on the current version of CC and it has stopped working. Can anyone help? Please? Here is the erorr.

 

CherylC_0-1644853775696.png

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Feb 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

The text of the script has been slightly mangled, possibly by a forum re-vamp in the past. Here it is fixed up and tested on AI 2022 MacOS:

//Some utils to retrieve files in folders and subfolders
var api = {
    getFiles: function (fo, aExtensions, bRecursive, aFiles, includeFolder) {

        var exts = aExtensions ? aExtensions.join("|") : ".+";
        var pattern = new RegExp("\\.(" + exts + ")$");
        if (!aFiles) aFiles = [];
        var filterFunction = function (file) {
            return pattern.test(file.name);
        }

        if (bRecursive && fo.name.indexOf(".") != 0) {
            var foFiles = fo.getFiles();
            while (f = foFiles.shift()) {
                if (f instanceof Folder) {
                    if (includeFolder === true) files[files.length] = f;

                    this.getFiles(f, aExtensions, true, aFiles);
                }
                if (f instanceof File && pattern.test(f.name) && f.name != ".DS_Store") {

                    aFiles[aFiles.length] = f;
                }
            }

            return aFiles;
        }

        else {
            return fo.getFiles(filterFunction);
        }
    },
}


//Main routine
var main = function () {

    var fo = Folder.selectDialog("Please select a folder"),
        files, n = 0, doc, nFile,
        opts = new EPSSaveOptions();

    //Settings options
    // opts.… = …

    //Exit if no selected folder
    if (!fo) return;

    //getting AI files
    files = api.getFiles(fo, ["ai"], true);
    n = files.length;

    //Exit if no files found
    if (!n) {
        alert("No files found sorry");
        return;
    }


    //convert found files
    while (n--) {
        nFile = files[n];
        doc = app.open(nFile);
        doc.saveAs(File(nFile.parent + "/" + nFile.name.replace(/\.ai$/, '.eps')), opts);
        doc.close();
    }
}


//run
main();

 

Likes

Translate

Translate

Report

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
New Here ,
Mar 14, 2022 Mar 14, 2022

Copy link to clipboard

Copied

doesn't work 

Error 8: Errore di sintassi.
Line: 1
> {\rtf1\ansi\ansicpg1252\cocoartf2636

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Mar 14, 2022 Mar 14, 2022

Copy link to clipboard

Copied

LATEST

@Jeansevilla, your error is because you have saved the script as a rich text file (see the "rtf1" tag in the error message). You must save the script as a plain text file.

- Mark

Likes

Translate

Translate

Report

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