Reads a portion of a file into a string


      FileStr(<cFile>, [<nLength>], [<nOffset>],
             [<lCtrl-Z>]) --> <cCharacterstring>


<cFile> : Designates the file from which a string is read.

<nLength> : Designates how many characters you want to read from a file. The default is read all characters.

<nOffset> : Designates an offset within the file from which the

<nLength> : characters or the rest of the file, are read. The default is from the first character (0).

<lCtrl-Z> : If this parameter is designated as .T., only data up to the first Ctrl-Z is read in. The default is read all data (.F.).


<cCharacterstring> : the string read in from the designated file.


FileStr() also offers the capability to read files or a portion of them, into a string. This is only possible with a function call, where the file name may contain a drive and path designation. If you implement the <lCtrl-Z> parameter, you can be sure the function only reads data up to the first Ctrl-Z and ignores whatever might remains in of the file.

In contrast to the Fxxxx() functions, a disadvantage of FileStr() is a slower access speed, since the file you want to read cannot be held open.


      .  Read in a file completely:

         ? FileStr("C:\TEXT\TEST.TXT")            // Displays file text

      .  Read in everything to the first Ctrl-Z:

         cVar  := FileStr("C:\TEXT\TEST.TXT", .T.)

      .  The file TEST.TXT contains "ABCDEFGHIJ".  Four characters,
         beginning from position 3, are to be read:

         ? FileStr("C:\TEXT\TEST.TXT", 4, 3)      // "CDEF"

      .  Read the maximum that fits into the available working memory:

         cVar  := FileStr("C:\TEXT\TEST.TXT", MEMORY(1) *1024 -100)




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s