Page 1 of 1 1
Topic Options
#133180 - 2005-01-31 04:16 PM Maximum length of a text file ?
tonyh Offline
Getting the hang of it

Registered: 2002-01-09
Posts: 55
Loc: UK
Hi

Im using Kix32 4.2. Im trying to read from one test file and retrieve the last 32 characters from each line until the end of the list and place it the results into another txt file. The list file is well over 50000 lines. The kix script keeps on ending before it gets even a 10th of the way down the list. Is there a maximum length for a file it can read or write to.

Heres the script

Break ON
CLS

:start

$=Open(1,"c:\mike\list.txt")
:read
Do $Line=ReadLine(1)
? "$line"
$x = Rtrim($line)
$y = Len("$x")
$machine = $x
If $x = "end"
Goto end
Else

$q=Right ("$x",32)

Shell 'cmd /c echo $q >> c:\mike\report.txt'

EndIf


:startagain
Until InStr($Line,"end")

:end
Shell 'cmd /c echo end of list'





thanks in advance

Tony


Edited by tonyh (2005-01-31 04:29 PM)
_________________________
Tonyh

Top
#133181 - 2005-01-31 04:43 PM Re: Maximum length of a text file ?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
First off, please use code tags to preserve indenting.
Second, do NOT use GOTO.
Third, do NOT wrap vars in quotes.
Fourth, do NOT embed vars in strings.

That said, did you try stepping through the code to see what is happening? Does it end on the same line every time? How long is the line it ends on?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#133182 - 2005-01-31 04:52 PM Re: Maximum length of a text file ?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
There used to be a 32kb limit on strings, but I didn't think it applied to files any more.

The following code is a bit tidier and easier to follow:
Code:
Break ON 
$=SetOption("WrapAtEOL","ON")

If Open(1,"c:\mike\list.txt") "Cannot open list.txt for reading"+@CRLF EndIf
If Open(2,"c:\mike\report.txt",1+4) "Cannot open report.txt for writing"+@CRLF EndIf

$Line=ReadLine(1)
While Not @ERROR And Not InStr($Line,"end")
$Line ?
$=WriteLine(2,Right(RTrim($Line),32)+@CRLF)
$Line=ReadLine(1)
Loop

$=Close(1)
$=Close(2)

? "Done." ?


Top
#133183 - 2005-01-31 04:56 PM Re: Maximum length of a text file ?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
PS both your original code and the code that I've just posted will stop if a line contains the text "end" anywhere in it.

You shouldn't need this check at all if you want to read the entire file.

If this is the case, change
Code:
While Not @ERROR And Not InStr($Line,"end")


to just read
Code:
While Not @ERROR


Top
#133184 - 2005-01-31 04:59 PM Re: Maximum length of a text file ?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The string limit is only reached if one manipulates the string as the code does.

I was going to suggest that the script not SHELL out 50,000 times but I can't count past four!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.045 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org