Function Reference


FileGetEncoding

Determines the text encoding used in a file.

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

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.
1 = Check entire file for UTF8 sequences (default)
2 = Check first part of file for UTF8 sequences (the same as FileOpen uses by default)

Return Value

Success: Returns the file encoding using similar values to the FileOpen function:
0 = ANSI
32 = UTF16 Little Endian.
64 = UTF16 Big Endian.
128 = UTF8 (with BOM).
256 = (without BOM).
Failure: Returns -1.

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


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