Click or drag to resize

StrToFile Function (String, String, Logic)

X#
Writes the contents of a character string to a file.

Namespace:  XSharp.VFP
Assembly:  XSharp.VFP (in XSharp.VFP.dll) Version: 2.21
Syntax
 FUNCTION StrToFile(
	cExpression AS STRING,
	cFileName AS STRING,
	lAdditive AS LOGIC
) AS LONG
Request Example View Source

Parameters

cExpression
Type: String
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.
cFileName
Type: String
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, X# automatically creates it.
lAdditive (for backward compatibility)
lAdditive
Type: Logic
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.

Return Value

Type: Long
Numeric; the number of bytes written to the file.
Remarks
An nFlags 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 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).
nFlagsHexDescription
0 (S2F_FLAG_OVERWRITE) (default)0x0000The file is overwritten with the character string (formerly lAdditive=.f.)
1 (S2F_FLAG_APPEND) 0x0001The string is appended to the end of the file (formerly lAdditive=.t.).
2 (S2F_FLAG_UNICODE_LE) 0x0002 Write a Little Endian 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
4 (S2F_FLAG_UTF8) 0x0004 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.
8 (S2F_FLAG_UNICODE_BE) 0x0008 Write a Big Endian Unicode Byte Order Mark (BOM) FE FF at the beginning of file. cExpression is assumed to be UNICODE, therefore no translation is performed. The file is overwritten
256 (S2F_FLAG_UNICODE_TEXT) 0x0100 Write the file to disk using the normal .Net Unicode text functions.
See Also