Writes the contents of a character string to a file.
|STRTOFILE(В ) does not write to hidden files when running Visual FoxPro on Windows 2000 and later.|
STRTOFILE(cExpression, cFileName [, lAdditive | nFlag])
- Specifies the character string that is written to the file. cExpression can be a literal character string, an expression that evaluates to a character string, or a character type variable, array element, or field.
- Specifies the name of the file to which the character string is written. Include a path with the file name if the file is in a directory other than the current default directory. If the file you specify does not exist, Visual FoxPro automatically creates it.
- lAdditive (for backward compatibility)
- Specifies whether the character string is appended to the end of the file. If lAdditive is true (.T.), the character string is appended to the end of the file. If lAdditive is false (.F.) (the default), the file is overwritten with the character string. You are asked if you want to overwrite an existing file if SET SAFETY is set to ON. If SET SAFETY is set to OFF, the file is overwritten without warning.
Beginning with Visual FoxPro 7, you can use the nFlag parameter instead of lAdditive which enables you to also chose to write UTF-8 and Unicode Byte Order Marks. The following table describes the valid nFlag values.
nFlag Bit Description
The file is overwritten with the character string (formerly lAdditive=.f.)
The string is appended to the end of the file (formerly lAdditive=.t.).
Write Unicode Byte Order Mark (BOM) FF FE at the beginning of file. cExpression is assumed to be UNICODE, therefore no translation is performed. The file is overwritten
Write UTF-8 Byte Order Mark (BOM) EF BB BF at the beginning of file. cExpression is assumed to be UTF-8, therefore no translation is performed. The file is overwritten.
Numeric; the number of bytes written to the file.
An nFlag value of 3 or 5 is not valid. You cannot attempt to write a new Byte Order Mark if nFlag bit 1, Additive, is set.
Unlike earlier versions of Visual FoxPro, STRTOFILE(В ) opens a file in Shared rather than Exclusive mode. This is useful when multiple servers attempt to simultaneously write to the same file. Because of this change, you might not need to check for STRTOFILE(В ) to return 0 (failure to open a file).