Skip to main content
Participant
April 9, 2018
Answered

Batch convert .ai to .eps including subfolders

  • April 9, 2018
  • 6 replies
  • 6572 views

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

This topic has been closed for replies.
Correct answer Loic.Aigon

//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

6 replies

Participant
November 28, 2023

Hi
Can someone post a step-by-step guide on how to action the script on Macosx please? I am completely lost!

Nicky G.
Known Participant
April 21, 2023

I am using this script to convert all EPS files, to AI.
The script works fine, I just want to:

1. when opening an error file the script continues to process the other files

2. when the MISSING FONT window appears, the window can be closed by itself and to put the conversion operation in AI (even without the font)

3. when it gives me the CMYK required notice go ahead

4. which can suppress any window that requires manual Acceptance by the user.

5. Do you know any other script maybe better than this one?

---------- [ CODE ] -----------------

//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("Selezionare la cartella Sorgente! [eps, pdf, svg, ai ]"),
files, n = 0, doc, nFile,
opts = new IllustratorSaveOptions();
//Settings options
// opts.… = …
//Exit if no selected folder
if ( !fo ) return;


/////////// GETTING AI FILES //////////

//files = api.getFiles ( fo, ["eps", "ai", "pdf","svg"], true );

//files = api.getFiles ( fo, ["eps", "EPS", "ai", "AI"], true );
//files = api.getFiles ( fo, ["ai", "AI"], true );
files = api.getFiles ( fo, ["eps", "EPS"], true );

n = files.length;
//Exit if no files found
if ( !n ) {
alert( "Nessun file è stato trovato." );
return;
}
//convert found files
while ( n-- ) {
nFile = files[n];
doc = app.open ( nFile );
doc.saveAs ( File ( nFile.parent+"/"+nFile.name.replace ( /\.eps$/, '.ai' ) ), opts );
doc.close();
}
}
//run
main();

Bpreuss
Participant
October 27, 2020

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

 
Bpreuss
Participant
October 27, 2020

I am also going from eps to ai now.

renél80416020
Inspiring
October 28, 2020

Bonjour,

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

//Main routine ligne 33

 

 

m1b
Community Expert
Community Expert
May 31, 2020

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

Charu Rajput
Community Expert
Community Expert
June 1, 2020

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

 

Best regards
m1b
Community Expert
Community Expert
June 1, 2020

👍

Participant
May 31, 2020

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

renél80416020
Inspiring
May 31, 2020

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

 

 

Participant
June 5, 2020

tnx a lot .

Cheryl CAuthor
Participant
April 9, 2018

I am using CS6.

Loic.Aigon
Loic.AigonCorrect answer
Legend
April 10, 2018

//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

Participant
August 7, 2018

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.