Hi, below is a script I hobbled together from various sources using the search function on this forum. It is supposed to change hyphens to en-dashes in a ai files in a folder. However, when I run it, it only works on one file. After it makes the change and closes the first file, it stops. Can anyone help me troubleshoot and fix the problem?
var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;
sourceFolder = Folder.selectDialog;
if ( sourceFolder != null )
{
files = new Array();
fileType = "*.ai";
files = sourceFolder.getFiles( fileType );
if ( files.length > 0 )
{
destFolder = sourceFolder;
for ( i = 0; i < files.length; i++ )
{
sourceDoc = app.open(files[i]); // returns the document object
var active_doc = app.activeDocument;
var search_string = '-';
var replace_string = "\u2013";
var text_frames = active_doc.textFrames;
if (text_frames.length > 0)
{
for (var i = 0 ; i < text_frames.length; i++)
{
var this_text_frame = text_frames[i];
var new_string = this_text_frame.contents.replace(search_string, replace_string);
if (new_string != this_text_frame.contents)
{
this_text_frame.contents = new_string;
}
}
sourceDoc.save();
sourceDoc.close();
}
}
}
}