Alienhead Posted January 16, 2023 Share Posted January 16, 2023 I need to append some text to the end of a file, I couldn't find any append to file functionality for this so I created a work around.. -------------------------------------------------------------- function CreateNewProfile(fname) -- add profile to master profile list local f_masterlist = FileSystem:OpenFile("saves/index.hdr") local f_temp = FileSystem:WriteFile("saves/temp.file") while (not f_masterlist:EOF()) do local readit = f_masterlist:ReadLine() f_temp:WriteLine(readit) end -- append new profile f_temp:WriteLine(fname) -- close files f_masterlist:Release() f_temp:Release() -- delay(1000) -- delete and rename master list files FileSystem:DeleteFile("saves/index.hdr") FileSystem:RenameFile("saves/temp.file","saves/index.hdr") end The read and writing works fine but it will not delete the old file and or rename the new file. ** Note: I have sandbox off. Is it safe to use lua's i/o commands? -- Opens a file in append mode file = io.open("test.lua", "a") Quote I'm only happy when I'm coding, I'm only coding when I'm happy. Link to comment Share on other sites More sharing options...
Josh Posted January 16, 2023 Share Posted January 16, 2023 I don't see anything wrong with your code. You could try to manually delete the file after this routine runs. If you are able to delete it, maybe there is a permissions issue. If the file is locked then the program isn't closing the stream. It's better to use ReadFile instead of OpenFile, in this situation, although that shouldn't make any difference. Lua's IO commands are fine to use. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.