在Applescript中合并文件

在Applescript中合并文件,applescript,Applescript,我正试图在AppleScript中完成以下操作 将在特定文件夹中找到的所有*.xxx文件连接/合并到一个新文件中 每个文件都包含一个头。合并前,从除第一个文件以外的所有文件中删除标题 将页脚文本添加到合并文件中 这在其他语言中听起来相对简单,但我是applescript的初学者。如果您能帮我找到方向,我们将不胜感激 短暂性脑缺血发作 如果您尝试此操作,系统会提示您选择基本文件夹和目标文件名 重要提示:使用基本文件夹之外的目标位置,以避免合并过程中包含的文件 我假设您的tsv文件类型是一个打字

我正试图在AppleScript中完成以下操作

  • 将在特定文件夹中找到的所有*.xxx文件连接/合并到一个新文件中
  • 每个文件都包含一个头。合并前,从除第一个文件以外的所有文件中删除标题
  • 将页脚文本添加到合并文件中
这在其他语言中听起来相对简单,但我是applescript的初学者。如果您能帮我找到方向,我们将不胜感激

短暂性脑缺血发作
如果您尝试此操作,系统会提示您选择基本文件夹和目标文件名

重要提示:使用基本文件夹之外的目标位置,以避免合并过程中包含的文件

我假设您的
tsv
文件类型是一个打字错误,您的意思是
csv

如果没有,请更改脚本中出现的所有
csv

文本分隔符为
linefeed
0A
),如果需要
return
0D
),请将
linefeed
的出现更改为
return

set baseFolder to choose folder
set destinationFile to choose file name with prompt "Choose destination file name" default name "merged.csv"
tell application "Finder" to set tsvFiles to (files of baseFolder whose name extension is "csv") as alias list
set text item delimiters to linefeed
try
    set fileDescriptor to open for access destinationFile with write permission
    repeat with i from 1 to (count tsvFiles)
        set theFile to item i of tsvFiles
        set theText to paragraphs of (read theFile as «class utf8»)
        if i = 1 then
            write (theText as text) to fileDescriptor as «class utf8»
        else
            write ((items 2 thru -1 of theText) as text) to fileDescriptor as «class utf8»
        end if
    end repeat
    close access fileDescriptor
on error
    try
        close destinationFile
    end try
end try
set text item delimiters to {""}

其强度取决于文件的确切结构/内容。哦,是的。假设有5列和10行文本。我主要是看帮助如何读取文件,循环它来读取整个内容。和合并。请更具体一些。脚本编写/编程是一项非常精确的业务。我们在谈论CSV吗?什么是文本编码?UTF8,拉丁语还是别的什么?很抱歉之前没有提供详细信息,我不知道这很重要。该文件似乎是一个.tsv文件。不确定文本编码。我可以看一下这个文件吗。看起来像是包含日期、时间、测试名称、通过/失败结果等列的简单文本。抱歉,在AppleScript中读取/写入文本取决于文本编码,因为UTF8、UTF16和其他文本的处理方式不同。