Game Development Community

Writing a script to the first line of a file without overwriting it?

by Roman Gwatyt · in Technical Issues · 10/06/2009 (4:10 pm) · 5 replies

Hey. I need to write a string to a new line at the top of a file without overwriting the file. It's a .cs file. Currently I can write to the string to a file, but it overwrites the contents of the file. This is using the openforwrite and writeline commands.

Here's an example of what I need; this is what the file contains already:

"//This is the file
function foo()
{"

I need it to write to the file, and come out like this:

"//New line here
//This is the file
function foo()
{"

Thanks.

About the author

Recent Threads

  • De-lagging?
  • CD-Key System?

  • #1
    10/06/2009 (8:07 pm)
    Your previous posts give me the impression that you are working with the source of TGE and are open to solutions with engine modifications. I can't see any licenses on your account, however. May I ask how you have licensed TGE?
    #2
    10/06/2009 (9:54 pm)
    I am working with someone who has a license, and yes, we are open to engine modifications if need be. However, I was hoping this wouldn't be something that would need it. Thanks.
    #3
    10/06/2009 (9:59 pm)
    Konrad, I'm licensed and working with the engine code. He's helping with scripting for my project and only has access to the compiled engine binaries.
    #4
    10/06/2009 (10:02 pm)
    I *think* we got this figured out via AIM though.
    #5
    10/07/2009 (5:56 am)
    Thanks for clarifying that guys.

    @Roman: a simple solution might be reading the contents of the file, and rewriting the file with the new contents appended to the beginning of the old contents. Would that work for you?