Announcement

Collapse
No announcement yet.

Sequentially re-reading a file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sequentially re-reading a file

    If I open a file for sequential reading of lines with:
    OPEN MyFile.txt FOR INPUT AS #1

    and read 2/3 of the contents, how do I start back at the top again?
    Do I have to close the file and re-Open it? IS that the only way or is there some little GoToTop command i am missing?




    ------------------
    Kind Regards
    Mike

  • #2
    From the help file:

    SEEK [#] filenum, position

    Works for sequential access (0 = top of file). It worked fine for me in DOS.

    regards,

    ------------------
    [email protected]
    :) IRC :)

    Comment


    • #3
      On a side note, to speed up reading a sequential file, add a LEN=8192 clause to the OPEN statement. For a sequential file, this tells PowerBASIC to use an internal buffer when getting data from the file, usually increasing read speed quite dramatically.

      You can specify a much larger value which will improve things even more, however, when reading across a network, 8192 is about the ("rule of thumb") optimal buffer size to avoid network saturation.

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        thx Ian I will try that,

        Cool Lance, I wrote it like this:
        OPEN SourceFile FOR INPUT AS 100 LEN = 8192

        I am compiling a huge file from many smaller ones. Each "small one is 22k lines. I have about 10 of them to compile (is there a limit to the size of a .txt file?)

        I assume the 8192 is the number of bytes?

        Im not on a network so can I allocate a much bigger chunk of memory like say 500k or even 1MB?

        ------------------
        Kind Regards
        Mike

        Comment


        • #5
          Correct on all counts.

          The file size is a limit of the O/S, so for WIn95a it is around 2Gb, larger for latter versions of Windows (using Fat32, NTFS, etc).

          PowerBASIC itself uses the QUAD integer range for byte/record access to files. Thats a lot of bytes and records!


          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]erbasic.com</A>
          Lance
          mailto:[email protected]

          Comment

          Working...
          X