Raised This Month: $ Target: $400
 0% 

Writing first line of a file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 01-17-2013 , 23:56   Writing first line of a file
Reply With Quote #1

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.
DjOptimuS is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-18-2013 , 00:16   Re: Writing first line of a file
Reply With Quote #2

Why do you need something like this?
__________________
Impossible is Nothing
Sylwester is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-18-2013 , 00:51   Re: Writing first line of a file
Reply With Quote #3

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.
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-18-2013 , 01:00   Re: Writing first line of a file
Reply With Quote #4

Just use write_file(const file[],const text[],line = -1), with line index == 0.
For everything else, use new file system.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 01-18-2013 , 08:46   Re: Writing first line of a file
Reply With Quote #5

thank you, i will give a try these days
DjOptimuS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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