Hi, I hope that someone can help me solving a stack overflow error that I get when running a script I created. I’ve pasted part of the script below. What the script does is read a text file and then split it into a number of smaller text files. The names of the smaller text files are already in the big text file. These names are between “&&&—” and “—&&&”. All the text after “—&&&” up until the next occurence of “&&&—” is text that needs to be put into a separate text file. I hope this is clear. Anyway, the script runs fine for smaller text files, but with larger text files (>25K) I get a “stack overflow” error. I have no idea why. Any suggestions are very welcome! I’ve given the script loads of memory but that doesn’t help at all… (I’m not a progammer at all, far from it, as you can probably tell from the script I pasted below.) Thanks - Roja
repeat
try
--i'm using the osax DTFindString even though I guess I don't really need it
DTFindString "&&&---" in fileContents starting at searchFrom
on error errMsg number errNum
--DTFindString returns errNum -1 when it can't find the search string
if errNum = -1 then exit repeat
end try
set firstCharOfFileName to result + 6
DTFindString "---&&&" in fileContents starting at searchFrom
set lastCharOfFileName to result - 1
set shortFileName to (characters firstCharOfFileName thru lastCharOfFileName of fileContents) as string
set firstCharOfMainText to lastCharOfFileName + 8
DTFindString "&&&---" in fileContents starting at firstCharOfMainText
set lastCharOfMainText to result - 2
-- the next line is where the "stack overflow" error occurs after a number of text files have been created just fine
set mainText to (characters firstCharOfMainText thru lastCharOfMainText of fileContents) as string
tell application "Finder"
set outFile to ((path to preferences folder as string) & "QXP:" & shortFileName) as string
set fileRef to open for access outFile with write permission
write mainText to fileRef
close access fileRef
end tell
set searchFrom to lastCharOfMainText
end repeat