On Apr 8, 2007, at 2:13 PM, Erik Mikysa wrote: I would like to figure out how I can take one text file (the output of a data merge) and automatically process it into multiple files, each containing the appropriate delimited content. For instance, if the main original text file had the following content:
set Original_text to (read (choose file with prompt "Choose the file to process.")) set the destination to (choose folder with prompt "Choose the folder to save the files in." default location (path to documents folder)) as text
set text item delimiters to "[break-into-file-with-name:" set the paras to the rest of the text items of the Original_text repeat with Para in the paras set {title, content} to breakdown(Para) set fileRef to open for access destination & title with write permission set eof of fileRef to 0 write content to fileRef close access fileRef end repeat
on breakdown(input) set text item delimiters to "]" return {text item 1 of input, text items 2 through end of input} end breakdown
The reason it's "text items 2 through end of input as text" instead of "text item 2 of input" is to take into account whether there are any right brackets in the text.
The reason for "rest of" is that for some reason the first text item is a null string. "Rest of" returns text items 2 through -1 of the list.
-- Michelle
-- Only in in the USA do they have a General in charge of the post office and a Secretary in charge of defense.
|