Function Reference


FileGetEncoding

Determines the text encoding used in a file.

FileGetEncoding ( "filehandle/filename" [, mode = 1] )

Parameters

filehandle/filename The handle of a file, as returned by a previous call to FileOpen(). Alternatively you may use a string filename as the first parameter.
mode [optional] The UTF8 detection mode to use.
    $FE_ENTIRE_UTF8 (1) = Check entire file for UTF8 sequences (default)
    $FE_PARTIALFIRST_UTF8 (2) = Check first part of file for UTF8 sequences (the same as FileOpen() uses by default)

Constants are defined in FileConstants.au3.

Return Value

Success: the file encoding using similar values to the FileOpen() function:
    $FO_UTF16_LE (32) = UTF16 Little Endian.
    $FO_UTF16_BE (64) = UTF16 Big Endian.
    $FO_UTF8 (128) = UTF8 (with BOM).
    $FO_UTF8_NOBOM (256) = UTF8 (without BOM).
    $FO_ANSI (512) = ANSI (containing char > 127 and < 255)
Failure: -1.

Constants are defined in FileConstants.au3.

Remarks

If a filename is given rather than a file handle - the file will be opened and closed during the function call.
Note: Do not mix filehandles and filenames, i.e., don't FileOpen() a file and then use a filename in this function. Use either filehandles or filenames in your routines, not both!

If a file handle is used then the "mode" parameter has no effect - the mode used for FileOpen() takes precedence.

Related

FileOpen, FileRead, FileReadLine, FileWrite, FileWriteLine

Example

#include <MsgBoxConstants.au3>

Example()

Func Example()
        Local $iEncoding = FileGetEncoding(@ScriptFullPath) ; Retrieve the file encoding of the current script.
        If @error Then
                MsgBox($MB_SYSTEMMODAL, "", "Error: Could not obtain the file encoding.")
        Else
                MsgBox($MB_SYSTEMMODAL, "", "FileGetEncoding: The value returned was: " & $iEncoding) ; The value returned for this example should be 0 or $FO_ANSI.
        EndIf
EndFunc   ;==>Example