1

我有一个文件:

A

Some text

Sum up

MaxScript我可以使用's轻松创建该文件format "..." to:file

但是如何在已经存在而不是空的文件中添加一些行

大多数情况下,我想添加以下my text

  1. 在指定文本出现之后(例如Some text,在新行之后)
  2. 在指定行(例如在空行 #4 并在其后添加新行)

如果不可能,那么也许我可以在文件中附加一些东西(写在之后Sum up)?


ps 我总是可以将整个文件读取到变量中,将我的文本添加到其中,然后保存文件。

但这并不是大文件的真正选择(我想让它更快)。

4

1 回答 1

4

要附加到文件,请使用带有“a”作为模式参数的 openFile。完整的文档可以在FileStream Values中找到:

fs = openFile "c:/Temp/YourFile.txt" mode:"a"
print "This line will be appended to your file" to:fs
close fs

-- Insert some text in the middle of a file
fsadd = openFile "c:/Temp/YourFile.txt" mode:"a+"
skipToString fsadd "Some text to write"
skipToNextLine fsadd
print "Insert New Text" to:fsadd
close fsadd
于 2014-03-29T23:16:29.240 回答