merging multiple files

I found quite a few script explaining how to merge multiple files within 1 folder.

But I need a script where I can point the (text) files and then merge into new file on the desktop.

The script works fine with 1 text file but gives me the

Can’t make quoted form of POSIX path of {alias “Macintosh HD:Users:Kemal:Desktop:log1.txt”, alias “Macintosh HD:Users:Kemal:Desktop:log2.txt”} into type Unicode text.

error with multilpe files. How can I get this script working ?

any help is appreciated!

set filez to choose file with prompt "Choose  file(s)" with multiple selections allowed

set loc to path to desktop

do shell script "cat " & quoted form of POSIX path of filez & ">" & quoted form of POSIX path of loc & "tezt.txt"


Hello Kemalski,

Try this out:

set folder_ to (choose folder with prompt "Select the folder containing .txt files.")
set output_ to (choose file name with prompt "Choose a name and location for the merged file.")
tell application "Finder" to set files_ to files of folder_ as alias list

	set file_ref to open for access output_ with write permission
	repeat with file_ in files_
		set text_ to read file_
		write (text_ & return) to file_ref starting at eof
	end repeat
		close access file_ref
	end try
on error e
	display dialog e
		close access file_ref
	end try
end try

The will ask you for your folder containing the text files and then the final merged file will be in the location you specified. Hope that helps…


Thank you. I altered it to work with files in stead of folder but it works. Now I want more offcourse :slight_smile:


Oh you’re welcome. This forum has helped me tremendously, and now it’s time to give back!