PtokaX forum

Development Section => Your Developing Problems => Topic started by: kepp on 17 February, 2004, 12:41:53

Title: How do i Overwrite things in a file?
Post by: kepp on 17 February, 2004, 12:41:53
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 :)
Title:
Post by: c h i l l a on 17 February, 2004, 12:51:24
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.
Title:
Post by: kepp on 17 February, 2004, 13:20:37
so with other words, It's not possible? :D
Title:
Post by: Herodes on 07 July, 2004, 00:50:10
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
Title:
Post by: Corayzon on 07 July, 2004, 01:23:41
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
Title:
Post by: kepp on 09 July, 2004, 21:20:41
Nevermind, Would require too much of code for nothing