Author Topic: WriteFile changed?  (Read 1007 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
WriteFile changed?
« on: May 19, 2007, 01:22:38 pm »
WriteFile used to replace everything with the inputed text, but now it only adds it to the beginning. How can I delete some text in a text file?

I'm basically trying to modify a specific line, where as the the line thats being edited doesn't matter what line it ends up on...

I used to have:
Code: [Select]
      File := XSplit(ReadFile('CashSpot.txt'),chr(13) + chr(10));
      Spot := -1;
      i := 1;
      while (i <> Spot) and (i <= GetArrayLength(File) - 1) do begin
        if Copy(File[i],1,Length(IDtoName(ID))) = IDtoName(ID) then Spot := i;
        if i <> Spot then i := i + 1;
      end;
      if Spot <> -1 then begin
        WriteFile('CashSpot.txt','');
        for i := 0 to GetArrayLength(File) - 1 do begin
          if (i < Spot) then WriteLnFile('CashSpot.txt',File[i]);
          if (i > Spot) then WriteLnFile('CashSpot.txt',File[i - 1]);
        end;
      end;
      WriteLnFile('CashSpot.txt',IDtoName(ID) + 'Æ' + EndText);
But it no longer clears the file :'(

Is there any way at all to delete / modify text in a file?

NOTE: im using the 2.6.1 dedicated server pre-release for this
« Last Edit: May 19, 2007, 01:27:30 pm by DorkeyDear »