Jump to content

Can't solve this one


Alienhead
 Share

Recommended Posts

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")

 

I'm only happy when I'm coding, I'm only coding when I'm happy.

Link to comment
Share on other sites

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.

  • Like 1

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...