How to combine several RTF files to one file?

I have a folder full of several RTF files which I would like to combine to one file.

Can this be done using AppleScript ( maybe via Microsoft Word 2004 or TextEdit )?

If so, how?

Kari

The following works for me with Word 2004

set FldAlias to choose folder “Choose your folder of RTF”

tell application “Finder”
set rtfFiles to every file of FldAlias
end tell

tell application “Microsoft Word”
set combineDoc to make new document
repeat with rtffile in rtfFiles
open rtffile
set curDoc to the active document
insert text the content of the text object of curDoc at the end of the text object of combineDoc
close curDoc saving no
end repeat
end tell

jimmur,

I tried your script, but could not get it to work - without modifying it to this:

The problem is that combined file loses all the styling and I really need to retain all styles intact.

So, how do I modify this line:
insert text the content of the text object of curDoc at the end of the text object of combineDoc
to insert file which retains all the styling?

I tired this:
insert curDoc at the end of combineDoc
but without succes…

Kari

Sorry I should have thought about the formatting.

This should work for you.

tell application "Microsoft Word"
	set the_folder to choose folder "Choose your folder of RTF files"
	set the_files to (my get_folder_list(the_folder, "rtf"))
	set combineDoc to make new document
	repeat with rtffile in the_files
		open rtffile
		set curDoc to the active document
		select the text object of curDoc
		copy object selection
		close curDoc saving no
		collapse range text object of combineDoc direction collapse end
		paste object selection
	end repeat
end tell

on get_folder_list(the_folder, file_extension)
	set the_files to {}
	tell application "Finder" to set folder_list to every file of folder the_folder whose name ends with file_extension
	repeat with new_file in folder_list
		copy (new_file as string) to end of the_files
	end repeat
	return the_files
end get_folder_list

jimmur,

Thank you, this works fluently!

Microsoft Word 2004 Dictionary and Object Model is a new thing to me, and I must say that I found both of them to be a quite weird!

I couldn’t even think about that there could be such thing!

Kari