Why my script does not work on all files in the folder?

Hi , here's a script I've hobbled together from various sources using the search function on this forum. It is supposed to replace dashes quadratins in a file in a folder. However, when I run it, it only works on a single file. After making the changes and closes the first file, it stops. Can someone help me troubleshoot and resolve the problem?

var destFolder sourceFolder, files, type sourceDoc file, targetFile, pdfSaveOpts;

sourceFolder = Folder.selectDialog;

If (sourceFolder! = null)

{

files = new Array();

fileType = "* .ai;

files = sourceFolder.getFiles (file type);

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

}


}

}

}

you use the same variable (var I =...) for two loops, when you start to treat the first file I = 0, then after that loop you through all managers of related texts, I = 10 for example, then he wants to treat the next file, file [11] and if you have fewer files, it will stop, if you have more than 10 then it will continue...

.. .change one of them to something else (var j =...)

Tags: Illustrator

Similar Questions

Maybe you are looking for

  • iPhone connect to iTunes

    I have an iPhone 6 running iOS10. "Whenever I connect my iPhone to my laptop, which runs windows 7, iTunes come and gives me this message: iTunes could not connect to the iPhone (the iPhone name) because an invalid response was received from the devi

  • Satellite C660: the system stops when I use internet or read a file

    for 2 days the laptop (I have win7 Home premium) hang up when I use internet, play a game, use a program, read a document. I'm not be able to move the mouse pointer and also pressing CTRL-ALT - ANNU system stops too. The only way to turn off the lapt

  • How to play M2T format

    I received that, in my view, are photos (maybe videos) of my grandchildren on memory cards SDHC my MacBook Pro cannot read. Looks like it's a M2T format... Could someone help. Thank you Norbert

  • Case structure works is not as expected

    Hello all I have a business structure which does not seem to work there in the State on. I created the circuit 1st in 1st red slice and it works each led flashes on then off in sequence, but when I try this logic in a case statement (in the 2nd red b

  • 15 - r210dx: Wireless driver problem

    My laptop comes with windows 8. But I wanted to use windows 7 64 bit which I'm more comfortable with it. I used diskpart and erase all the data and then converted the HARD of GPT on the MBR disk. Then I installed 7 easily. Now the question is, I down