AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Writing first line of a file (https://forums.alliedmods.net/showthread.php?t=206070)

DjOptimuS 01-17-2013 23:56

Writing first line of a file
 
Hello,

Is there a way to write the first line of a file and keep the other lines already written ?

For example:

-> Line 5
-> Line 4
-> Line 3
-> Line 2
-> Line 1

We can call it a reverse from the log_to_file function. The only difference is that the text written inside of the file will be on a reversed order.

Also, if possible, to keep only a specific number of lines, for example maximum 100.

I found a sample from PHP but I think that copying the entire file content into memory, just to add one more line then rewrite the new content is bad for memory.

I am wondering if it's possible to write something on the first line of a file without copying the entire file content.

Thank you.

Sylwester 01-18-2013 00:16

Re: Writing first line of a file
 
Why do you need something like this?

fysiks 01-18-2013 00:51

Re: Writing first line of a file
 
It might be possible IIRC but it would always just overwrite was is already there I think. However, there is probably a better alternative to your supposed method. So, answer Sylwester so we can get a better idea of what you actually want to do.

ConnorMcLeod 01-18-2013 01:00

Re: Writing first line of a file
 
Just use write_file(const file[],const text[],line = -1), with line index == 0.
For everything else, use new file system.

DjOptimuS 01-18-2013 08:46

Re: Writing first line of a file
 
thank you, i will give a try these days


All times are GMT -4. The time now is 13:35.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.