Determines the likely character set encoding of a text file.
FileEncoding (filename)
(s) filename either a fully qualified filename with drive and path, or just a filename and extension.
(i) number indicating the character set (see below.)
FileEncoding uses multiple algorithms to determine the probable character set used to represent a file's text.
Note: filename file size is limited to approximately 700MB with 32-bit WinBatch and 2GB with 64-bit WinBatch.
The returned number has one the following meanings:
Return Number |
Character Set |
0 |
unknown (likely binary) |
1 |
ANSI (or UTF-8) |
2 |
UTF-16 LE (Windows Unicode) |
3 |
UTF-16 BE (reversed two byte Unicode) |
4 |
UTF-8 |
5 |
Extended ANSI (or MBCS but not UTF-8) |
Note: this function performs statistical analysis and pattern detection to determine a file's character encoding and it usually makes the correct determination. However, some byte patterns may cause the function to return an incorrect result.
This function supports extended-length path names.
file = DirScript():"stuff.txt" encoding = FileEncoding(file) ; Convert the character encoding to something human readable. mesbody = file:"'s character set:":@lf:@lf Switch encoding Case 0 mesbody := "binary" Break Case 1 mesbody := "ANSI" Break Case 2 mesbody := "UTF-16 LE" Break Case 3 mesbody := "UTF-16 BE" Break Case 4 mesbody := "UTF-8" Break Case 5 mesbody := "Extended ANSI" Break EndSwitch ; Display the determination. Pause("File Encoding", mesbody) :cancel Exit