applescript文件名错误

applescript文件名错误,applescript,filenames,Applescript,Filenames,我有一个电子表格,我们办公室用来安排日程。每个选项卡表示一个月。我可以将每个选项卡导出到名为month1.csv、month2.csv的文件中。。。等等。我有以下代码打开每个月的文件并循环: repeat with b from 1 to 12 tell application "Finder" set curFileName to (sourceFolder & "month" & b & ".csv") as s

我有一个电子表格,我们办公室用来安排日程。每个选项卡表示一个月。我可以将每个选项卡导出到名为month1.csv、month2.csv的文件中。。。等等。我有以下代码打开每个月的文件并循环:

    repeat with b from 1 to 12
            tell application "Finder"
            set curFileName to (sourceFolder & "month" & b & ".csv") as string
            --display dialog curFileName
            set workingFile to read file (curFileName)
            --display dialog "File has been read"
            set AppleScript's text item delimiters to {ASCII character 13}
            set theContents to text items of workingFile as list
        end tell

do stuff with the csv...

end repeat
脚本在第一个月内迭代,然后当b=2时,我得到以下错误:

Finder got an error: File file Macintosh HD:Users:lorenjz:Documents:Manpower:,month,2,.csv wasn’t found.

要消除此错误,我需要做什么?

使用以下行,而不是您的行。基本上,您正在尝试将文本添加到一起以创建文件路径。但是,sourceFolder不是文本,所以必须先将其转换为文本,然后才能向其中添加更多文本。“b”也不是文本,因此也必须强制为文本

一般来说,applescript很适合为您强制执行某些内容。它基本上试图将所有内容强制到行中第一个对象的类中。所以,如果您将sourceFolder转换为文本(除非强制转换,否则它是一个文件说明符),那么applescript将尝试将之后的所有内容强制转换为文本。。。这意味着您真的不必强制“b”为文本,因为applescript会为您这样做。。。当然,只要souceFolder是文本。我通常会强迫自己,以确保它是正确的,所以我通常也会强迫自己“b”

关键是,当你将文本添加到一起时,所有内容都必须是文本。你不能仅仅把“作为文本”放在行的末尾,你必须强制每个单独的项目都变成文本。祝你好运

set curFileName to (sourceFolder as text) & "month" & (b as text) & ".csv"