Help home › The Family Historian API › Function Index › fhSaveTextFile

functions

fhSaveTextFile

Description

Saves a string to a text file.  Caution: If a file already exists with that name it will be replaced with no warning.  If it doesn't exist it will be created.    Any folders referenced must exist however or the call will fail.

This function never sets the conversion loss flag.

See also fhLoadTextFile.


Minimum FH Version

7 (ANSI file format requires a minimum of 7.0.10)

Syntax

bOK = fhSaveTextFile(strFilePath, strContents[, strFileFormat])

Parameters

strFilePath
Full path name of the text file to save to.
strContents
The string to be written out to the file.    Note: regardless of the required output file format, the encoding of this string must match the current string encoding - i.e. UTF8 or ANSI.  For more information, please see String Encoding and Unicode.
strFileFormat
The text format of the file.  Optional.  If supplied, this must be "UTF-8", "UTF-16LE" (UTF-16, little endian) or "ANSI".  If not supplied it defaults to "UTF-8".

Returns

bOK
Boolean.  True = success.  False = failure.

Example

local bOK = fhSaveTextFile(strFilePath, "Hello world!", "UTF-8");
if (bOK)
    fhMessageBox("Success!");
else 
    fhMessageBox("Save failed");