Skip to main content
Participant
May 31, 2020
Answered

changing eps to ai automatically by a script

  • May 31, 2020
  • 2 replies
  • 6390 views

can you help me for changing eps to ai automatically by a script . I have a tons of Eps and need this 🙂

Correct answer Manan Joshi

Try the following code. This code was modified from the original source by Loic_Aigon in the thread mentioned below

https://community.adobe.com/t5/illustrator/batch-convert-ai-to-eps-including-subfolders/td-p/9746062?page=1

//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 IllustratorSaveOptions();
	//Settings options
	// opts.… = …
	//Exit if no selected folder
	if ( !fo ) return;
	//getting AI files
	files = api.getFiles ( fo, ["eps"], 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 ( /\.eps$/, '.ai' ) ), opts );
		doc.close();
	}
}
//run
main();

 

-Manan

 

2 replies

Manan JoshiCommunity ExpertCorrect answer
Community Expert
June 5, 2020

Try the following code. This code was modified from the original source by Loic_Aigon in the thread mentioned below

https://community.adobe.com/t5/illustrator/batch-convert-ai-to-eps-including-subfolders/td-p/9746062?page=1

//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 IllustratorSaveOptions();
	//Settings options
	// opts.… = …
	//Exit if no selected folder
	if ( !fo ) return;
	//getting AI files
	files = api.getFiles ( fo, ["eps"], 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 ( /\.eps$/, '.ai' ) ), opts );
		doc.close();
	}
}
//run
main();

 

-Manan

 

-Manan
Nicky G.
Known Participant
April 16, 2023

This script looks for *.EPS files and converts them to *.Ai ...
Everything OK.

It would be possible to implement after the file conversion, if the conversion was successful and in the folder where you got the EPS, do a comparison, if there is a file myfile.eps & myfile.ai, remove the EPS file.

 

 

----------------------

//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 IllustratorSaveOptions();
//Settings options
// opts.… = …
//Exit if no selected folder
if ( !fo ) return;
//getting AI files
files = api.getFiles ( fo, ["eps"], 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 ( /\.eps$/, '.ai' ) ), opts );
doc.close();
}
}
//run
main();

hackettlai
Participating Frequently
December 5, 2024

I came across this while searching for similar solutions. Anyway, I added a few scripts to prompt the user to select whether they want to delete the original .eps files after all convert are complete.

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) aFiles[aFiles.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);
    }
  },

  deleteFiles: function (files) {
    for (var i = 0; i < files.length; i++) {
      files[i].remove();
    }
  },
};

// Main routine
var main = function () {
  var fo = Folder.selectDialog('Please select a folder'),
    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'], 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(/\.eps$/, '.ai')), opts);
    doc.close();
  }

  // Ask if the user wants to delete the original .eps files
  if (confirm('Do you want to delete the original .eps files?')) {
    api.deleteFiles(files);
  }
};

// Run
main();

 

dr_rapidAuthor
Participant
May 31, 2020

Hi guys
I need a way ( or script ) for convert EPS files to Ai ( i cant and dont want to use save as !)
basicly I have a lot of eps files that I need change them to ai format.
when I want to use the actions ( first and easily way )  , I should record an example for illustrator but after saving the file to a directory for changing to AI , THE DIRECTORY THAT I USED FOR EXAMPLE IS SAVED ON 'ACTION' , so for next EPS file it saves that to that directory that was on example . I want a way for export them to ai and each eps file from a folder should save to same folder

Can you help me ?!
TNX

Community Expert
June 5, 2020

This same question has been posted on the following thread

https://community.adobe.com/t5/illustrator/changing-eps-to-ai-automatically-by-a-script/m-p/11185071?page=1#M179970

I have answered it on the other thread. So i will lock this thread.

 

-Manan

-Manan