How do i Overwrite things in a file?
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

How do i Overwrite things in a file?

Started by kepp, 17 February, 2004, 12:41:53

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kepp

Ok, i have this problem..

When a new user arrives i save some information about him/her in a table, and then on a timmer that triggers ever 40 min i save those that are left in the table to a file..

It looks like this

?========|kepp|========?
Users Name : kepp
Users IP : 127.0.0.1
Users DNS : localhost
Users Share Amount : 6.68
Users Client : ++

now my problem is that i can end up with 10 kepp infos in that file..

What shall i do? Read the whole file and check for a spcific name and update it?
I still want to have everything, but if a user reenter with the same name i want it to overwrite his info!

I don't know so much about File I/O and therefor though of a little help!

Thanks in advance :)
Guarding    

c h i l l a

#1
create one file per user, or store the amount of saves per user in a table and work with that or... ;)

else if you find a way to update only certain lines in a text file I'd be quite happy to know how you did it.

kepp

so with other words, It's not possible? :D
Guarding    

Herodes

QuoteOriginally posted by kepp on 17.02.2004, 13:20
so with other words, It's not possible? :D

after 4 mnths, still nothing huh ? :S

Corayzon

hey kepp,

ull find that the only way to overwrite a line in a file, as you said, is to loop through and find the line your looking for and then update it. This sounds simple and is simple, but slow!

simply...

readfrom("file.txt")
local sLine = read()
local sOut

while sLine ~= nil do
	if not find username then
		sOut = sOut .. sLine
	end
	sLine = read()
end

readfrom()
writeto("file.txt")
write(newinfo .. sOut)
writeto()

now, ... what this does is check the username in each line of the file. if you find it then simply dont store it to sOut. Once the file is read, then add your new info the sOut and then write it to a file.

hope it helps, noza

kepp

Nevermind, Would require too much of code for nothing
Guarding    

SMF spam blocked by CleanTalk