StrFile

StrFile

Writes a string to a file

Syntax

      StrFile(<cCharacterstring>, <cFile>, [<lOverwrite>],
             [<nOffset>], [<lCutOff>]) --> <nRecordedByte>

Arguments

<cCharacterstring> : the character string to write to a file. <cFile> : File name. Drive and path designations are permitted, but no wildcards. <lOverwrite> : If NIL or .F., determines whether or not a new file is created. When .T., it writes to an existing file. The default is create new file (.F.).

<nOffset> : An offset within the file from which the <cCharacterstring> string is to be written. The default is End of file. <lCutOff> : When this optional parameter is designated as .T., the function truncates the file if data written ends before the last file byte. The default is no cut off (.F.).

Returns

<nRecordedByte> : the actual number of bytes written.

Description

This function provides another capability besides writing the contents of a string to a file. In contrast to the Fxxxx() functions, only one function call is necessary to write data to a file. However, it can result in some speed disadvantages, since files acted on by StrFile() cannot be held open. If the target file is unavailable, the StrFile() function always creates it.

Notes

. The attribute to create a new file, can be designated with the SETFCREATE() function.

. As recommended with the share mode, reads and writes from other network programs should be locked out with SETSHARE() for this period of time.

. This function acknowledges the setting for CSETSAFETY().

Examples

      .  Add to the end of a file:
         ? StrFile("ABCDEFGH", "TEST.TXT", .T.)             // Result: 8

      .  A file with drive and path designations, result: 10:

         ? StrFile("0123456789", "C:\TEXT\TEST.TXT", .T.)

      .  Data in an existing file is overwritten from position 20 with
         a designated string:

         ? StrFile("NANTUCKET", "TEST.TXT", .T., 20)        // Result: 9

      .  A 5-character string is written starting at position 10 in an
         existing file 20-characters long.  Since the final parameter is
         specified as .T. once, and specified as .F. once, you see different
         results:

         ? StrFile(REPLICATE("X", 20), "TEST.TXT")
         ? StrFile("AAAAA", "TEST.TXT", .T., 10, .F  // "XXXXXXXXXXAAAAAXXXXX"
         ? StrFile("AAAAA", "TEST.TXT", .T., 10, .T  // "XXXXXXXXXXAAAAA"

Seealso

FileStr()

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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