Author Topic: How do i Overwrite things in a file?  (Read 2173 times)

0 Members and 1 Guest are viewing this topic.

Offline kepp

  • Scripter
  • King
  • ******
  • Posts: 790
  • Karma: +2/-0
How do i Overwrite things in a file?
« 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 :)
Guarding    

PtokaX forum

How do i Overwrite things in a file?
« on: 17 February, 2004, 12:41:53 »

Offline c h i l l a

  • Lord
  • ***
  • Posts: 347
  • Karma: +1/-0
(No subject)
« Reply #1 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.
« Last Edit: 17 February, 2004, 12:52:39 by c h i l l a »

Offline kepp

  • Scripter
  • King
  • ******
  • Posts: 790
  • Karma: +2/-0
(No subject)
« Reply #2 on: 17 February, 2004, 13:20:37 »
so with other words, It's not possible? :D
Guarding    

Herodes

  • Guest
(No subject)
« Reply #3 on: 07 July, 2004, 00:50:10 »
Quote
Originally 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

Offline Corayzon

  • Lord
  • ***
  • Posts: 464
  • Karma: +1/-0
(No subject)
« Reply #4 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...

Code: [Select]
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

Offline kepp

  • Scripter
  • King
  • ******
  • Posts: 790
  • Karma: +2/-0
(No subject)
« Reply #5 on: 09 July, 2004, 21:20:41 »
Nevermind, Would require too much of code for nothing
Guarding    

PtokaX forum

(No subject)
« Reply #5 on: 09 July, 2004, 21:20:41 »