Author Topic: WriteFile/ReadFile issue  (Read 1339 times)

0 Members and 2 Guests are viewing this topic.

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
WriteFile/ReadFile issue
« on: April 21, 2008, 10:10:19 am »
At the moment I'm testing a new script and I often need to write and read files in order to get saved data.
I always get the content of the file + a blank line in the case I listed below. Therefore I'm worried about the Read- and WriteFile function ...

WriteFile(DatabaseFolder + 'LastBackup.txt', FormatDate('dd/mm/yy'));

// content should be a date like 21-04-08
LastBackup:= ReadFile(DatabaseFolder + 'LastBackup.txt');

// will show the date and a blank line ... confusing ???
WriteLn(LastBackup);


 I also tried to avoid this problem:

LastBackup:= GetPiece(ReadFile(DatabaseFolder + 'LastBackup.txt'), #13#10, 0);

This solution works fine ... but I'm wondering why none has the same problem. Is there any known bug or is the blank line shalled?

Greetings
Markus
Soldat Global Account System: #soldat.sgas @ quakenet

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: WriteFile/ReadFile issue
« Reply #1 on: April 21, 2008, 02:24:48 pm »
Im not sure, cause i haven't experimented a lot with writefile.
But in my lottery script i use readfile and xsplit to read lines from a file (file not made with writefile, btw). It always picks up an extra line at the end of the file which is empty.

Anyway, my guess is that it's in the readfile procedure.. not sure if you can call it a bug.
Come join: EliteCTF
Listen to: My Music

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: WriteFile/ReadFile issue
« Reply #2 on: April 21, 2008, 03:16:20 pm »
I'm not sure, cause i haven't experimented a lot with writefile.
But in my lottery script i use readfile and xsplit to read lines from a file (file not made with writefile, btw). It always picks up an extra line at the end of the file which is empty.

Anyway, my guess is that it's in the readfile procedure.. not sure if you can call it a bug.

I also know the problem with XSplit in combination with ReadFile and I think you're right. The blank line is caused rather to the ReadFile function than to the WriteFile function and XSplit is more or less irrelevant in this relation.

I'd like to know whether there is also a solution to avoid the blank line if you read a file and split it with XSplit.  I don't have any idea yet how to fix that problem ...

Thanks for suggestions  :)
« Last Edit: April 21, 2008, 03:21:02 pm by Markus Quär »
Soldat Global Account System: #soldat.sgas @ quakenet

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: WriteFile/ReadFile issue
« Reply #3 on: April 21, 2008, 04:34:33 pm »
mweh, there is always a solution.

Code: [Select]
SumArray := xplit(readfile(SumFile), #13#10)
SetArrayLenght(SumArray, (GetArrayLenght(SumArray)-1));

there could always be a more elegant one, ofcourse  ;D

edit: and look here my NUMBER ONE scripting-typo : lenght... TWICE!... im leaving it to punish myself  :-[
« Last Edit: April 21, 2008, 04:46:11 pm by JFK »
Come join: EliteCTF
Listen to: My Music

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: WriteFile/ReadFile issue
« Reply #4 on: April 23, 2008, 12:04:55 pm »
mweh, there is always a solution.

Code: [Select]
SumArray := xplit(readfile(SumFile), #13#10)
SetArrayLenght(SumArray, (GetArrayLenght(SumArray)-1));



there could always be a more elegant one, ofcourse  ;D

edit: and look here my NUMBER ONE scripting-typo : lenght... TWICE!... im leaving it to punish myself  :-[

*still laughing about your mistake :D*

Apart from fault, your solution is simple and works fine. God job JFK.
Soldat Global Account System: #soldat.sgas @ quakenet

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: WriteFile/ReadFile issue
« Reply #5 on: April 23, 2008, 01:24:17 pm »

*still laughing about your mistake :D*


in every script i make, im gonna just MAKE two extra procedures called 'getArrayLenght' and 'setArrayLenght'... at least it WORKS then :p
Come join: EliteCTF
Listen to: My Music