Skip to main content
Participant
Apr 9, 2018 12:47 PM UTC
Answered

Batch convert .ai to .eps including subfolders

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 is closed to new replies. Start a new post to keep the conversation going.
Loic.Aigon
Loic.AigonCorrect answer
Legend
Apr 10, 2018 10:59 AM UTC

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

20 replies

Participant
Nov 28, 2023 10:54 AM UTC

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

Translate
Nicky G.
Known Participant
Apr 21, 2023 7:22 AM UTC

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();

Translate
Bpreuss
Participant
Oct 27, 2020 12:55 PM UTC

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

 
Translate
Bpreuss
Participant
Oct 27, 2020 1:05 PM UTC

I am also going from eps to ai now.

Translate
renél80416020
Inspiring
Oct 28, 2020 6:35 PM UTC

Bonjour,

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

//Main routine ligne 33

 

 

Translate
m1b
Community Expert
Community Expert
May 31, 2020 10:20 PM UTC

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

Translate
Charu Rajput
Community Expert
Community Expert
Jun 1, 2020 5:57 AM UTC

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

 

Translate
Best regards
m1b
Community Expert
Community Expert
Jun 1, 2020 7:37 AM UTC

👍

Translate
Participant
May 31, 2020 7:13 AM UTC

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

Translate
renél80416020
Inspiring
May 31, 2020 1:48 PM UTC

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

 

 

Translate
Participant
Jun 5, 2020 12:06 PM UTC

tnx a lot .

Translate
Cheryl CAuthor
Participant
Apr 9, 2018 12:49 PM UTC

I am using CS6.

Translate
Loic.Aigon
Loic.AigonCorrect answer
Legend
Apr 10, 2018 10:59 AM UTC

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

Translate
Participant
Aug 7, 2018 8:05 PM UTC

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.

Translate