我正在尝试在AppleScript中执行以下操作。
在其他语言中听起来相对简单,但我是AppleScript的初学者。任何帮助找到方向将不胜感激。
TIA AnuRV
答案 0 :(得分:0)
尝试此操作时,系统会提示您选择基本文件夹和目标文件名。
重要说明:使用基本文件夹之外的目标位置,以避免文件包含在合并过程中。
我认为您的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 {""}