File merge


I’m trying to find an applescript which can take a folder of text files and merge them into one large text file.


Paco, Give this a shot.

property TheReturnKey : ASCII character 13
property theTextFilePath : ((path to startup disk) as text) & "Full Text File"
--This is where we choose the folder of text files.
tell the application "Finder"
set theFolder to choose folder with prompt "Choose Folder:"
set theFullText to ""
repeat with theFile in every item in theFolder
--We do an if statment so that the text file will not begin with a return.
if theFullText is "" then
set theFullText to theFullText & (read file theFile)
set theFullText to theFullText & TheReturnKey & (read file theFile)
end if
end repeat
--This is where we open and write the text file.
-- open prefs file with write access
set theTextFile to open for access file (theTextFilePath as text) with write permission
-- erase contents (start writing at position zero)
set eof theTextFile to 0
write theFullText as string to theTextFile
-- close the file
close access theTextFile
on error
close access theTextFile
end try
end tell