Computer Science Canada

how to delete data from a txt file?

Author:  JR [ Wed Mar 24, 2004 5:17 pm ]
Post subject:  how to delete data from a txt file?

ok, in my program i made it so it would erase the data variable, but lets say i put some data into the file, then i want to delete that data from the file not all the file only the data. how do i do that? cause my prog deleted the data from the variable and inorder to delete it on the file i need to save it agian.

Author:  Delos [ Wed Mar 24, 2004 5:45 pm ]
Post subject: 

First, read in the entire file.
Then remove the necassary data from RAM.
Then write the file.

Method wrote a good eg. a while back...I'll try find it then repost.

Ah well, can't find it...but, try the method above (hehehe...ah, the irony).

Author:  GUI.GetScrollBarWidth : i [ Thu Mar 25, 2004 11:54 am ]
Post subject: 

use file.deletetxt("filename") that will delete all the text in the file then you can write new stuff. that's the only way i knoww any way

Author:  Thuged_Out_G [ Thu Mar 25, 2004 3:49 pm ]
Post subject: 

i would go with delos's way. read the whole file, delete the parts you want. then write it back to the same file

Author:  Dan [ Thu Mar 25, 2004 5:07 pm ]
Post subject: 

i whould go with GUI's way, i think it whould be more effection if you whont to comply kill the old file.

Author:  Delos [ Thu Mar 25, 2004 5:32 pm ]
Post subject: 

Well, depends on what he wants to do really.
Wipe the file? GUI's method for sure.
Just bits and drabs? My method.

Author:  we64 [ Thu Mar 25, 2004 8:46 pm ]
Post subject: 

strongly agree with Delos. I think most of the time Delos' way is more useful.

Author:  Dan [ Thu Mar 25, 2004 10:27 pm ]
Post subject: 

that it is if u only whont to get ride scrent pices and not the hole thing witch he dose. i was just trying to say that but i think it made it look i ment that GUI's way is all ways better. But both will work fine realy and whould be very very close in exuction time.

if this is for a game the best way to go about it whould be to get all the data from the file at the start, do w/e with it to load th curnt spot in the game (asmuming it is for some kind of save file). keep mofining the vars during the game and the dump them back when u save your spot in the game. Also for a DB a method like that whould be a good idea as well. GUI's method whould be best for when u dont care waht is in the file and just whont it gone


: