2

我有一个写在文本文件中的数字。是否可以在文本文件中添加另一个号码,然后用新号码替换旧号码?这是我的代码:

set theFile to POSIX path of "Users:Tyler:Documents:File.txt"
open for access theFile
set theFileContents to read theFile

set theNewFile to run script theFileContents + 1
tell application "TextEdit"
set eof of theFileContents to 0
write theNewFile to theFileContents
4

1 回答 1

0

如果我正确理解了您的问题,您只想拥有一个带有字符串的文本文件并将该字符串转换为数字,然后将数字的值增加 1 将其作为字符串写回文件并保存,对吗?让我知道这是否是您的意思。

set docsFolder to path to documents folder

set afile to "" & docsFolder & "File.txt"
open for access file afile with write permission
set oldNum to read file afile
set newString to ((oldNum as number) + 1) as string
set eof file afile to 0
log newString
write newString to file afile starting at eof

close access file afile
于 2013-05-31T04:42:12.900 回答