shai Posted March 1, 2015 Share Posted March 1, 2015 (edited) hi i try to create text file with _FileCreate function that encode of this file will be "windows-1255" but i can't. the file always created in utf8 encode. i also tryed to do it with FileOpen($sFilePath, BitOR(2, 8)) and still is created in utf8 encode. thanks for all your solutions. Edited March 1, 2015 by shai Link to comment Share on other sites More sharing options...
Trong Posted March 1, 2015 Share Posted March 1, 2015 FileWrite("FileName.txt","ANSI Content") Regards, Link to comment Share on other sites More sharing options...
Developers Jos Posted March 1, 2015 Developers Share Posted March 1, 2015 and still is created in utf8 encode. What are you writing to the file? How do you determine it's encoding eand what is the encoding exactly.. UTF8 with or without BOM? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
shai Posted March 1, 2015 Author Share Posted March 1, 2015 What are you writing to the file? How do you determine it's encoding eand what is the encoding exactly.. UTF8 with or without BOM? Jos i writing simple text to the file when i open the txt file in notepad++ i see that file is utf8 WO BOM Link to comment Share on other sites More sharing options...
shai Posted March 1, 2015 Author Share Posted March 1, 2015 FileWrite("FileName.txt","ANSI Content") its also create file on utf8 WO BOM Link to comment Share on other sites More sharing options...
Developers Jos Posted March 1, 2015 Developers Share Posted March 1, 2015 i writing simple text to the file when i open the txt file in notepad++ i see that file is utf8 WO BOM So it is a regular file and Notead++ opens it as UTF8 without bom... the new SciTE will do the same to support multibyte chaacters by default. What is the simply text you write? Does it contain multi-byte characters? Show some code you use to create the file. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
shai Posted March 1, 2015 Author Share Posted March 1, 2015 even if i try this code: FileWrite("c:\FileName.txt","ANSI Content") the FileName.txt file is in utf8 Link to comment Share on other sites More sharing options...
Developers Jos Posted March 1, 2015 Developers Share Posted March 1, 2015 No it is not.... it is both ansi and utf8 without BOM as there are no special characters in there to indicate either one. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
shai Posted March 1, 2015 Author Share Posted March 1, 2015 (edited) how i can check what is the real encoding of output file? Edited March 1, 2015 by shai Link to comment Share on other sites More sharing options...
Trong Posted March 1, 2015 Share Posted March 1, 2015 (edited) a/ăexpandcollapse popupLocal $sFile = "FileToCheckEncoding.txt" Local $hfOpen = FileOpen($sFile, 2 + 8) FileWrite($hfOpen, "Đào Van Trong") ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF) $hfOpen = FileOpen($sFile, 2 + 8 + 32) FileWrite($hfOpen, "UTF16 Little Endian: Đào Văn Trong") ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF) $hfOpen = FileOpen($sFile, 2 + 8 + 64) FileWrite($hfOpen, "UTF16 Big Endian: Đào Văn Trong") ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF) $hfOpen = FileOpen($sFile, 2 + 8 + 128) FileWrite($hfOpen, "UTF8 (with BOM): Đào Văn Trong") ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF) $hfOpen = FileOpen($sFile, 2 + 8 + 256) FileWrite($hfOpen, "UTF8 (without BOM): Đào Văn Trong") ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF) ; * -----:| Func _GetFileEncoding($sFile) ; /*********************************************************************** * Trong ; * ---:| Function......: _GetFileEncoding($sFile) ; * ---:| Description...: Get File Encoding! ; ************************************************************************ * Local $sEndoding = FileGetEncoding($sFile), $sEncode $sEncode = $sEndoding If $sEndoding = 0 Then $sEndoding = "ANSI" If $sEndoding = 32 Then $sEndoding = "UTF16 Little Endian" If $sEndoding = 64 Then $sEndoding = "UTF16 Big Endian" If $sEndoding = 128 Then $sEndoding = "UTF8 (with BOM)" If $sEndoding = 256 Then $sEndoding = "UTF8 (without BOM)" If $sEndoding = -1 Then SetError(1, 0, -1) Return SetError(0, $sEncode, $sEndoding) EndFunc ;==>_GetFileEncoding ; * -----:|Edit:In Notepad++ Edited March 1, 2015 by Trong Regards, Link to comment Share on other sites More sharing options...
shai Posted March 1, 2015 Author Share Posted March 1, 2015 ok now i see that if i writing simple text is works but if i writing text from HTTP.ResponseText object the file swich to utf8. how i can keep the file in ansi format? Link to comment Share on other sites More sharing options...
Trong Posted March 1, 2015 Share Posted March 1, 2015 (edited) Local $sFile = "FileToCheckEncoding.txt" FileClose(FileOpen($sFile, 2 + 8)) Local $hfOpen = FileOpen($sFile, 1 + 8) FileWrite($hfOpen, "UTF8 to ANSI") FileClose($hfOpen) Edited March 1, 2015 by Trong Regards, Link to comment Share on other sites More sharing options...
shai Posted March 3, 2015 Author Share Posted March 3, 2015 Local $sFile = "FileToCheckEncoding.txt" FileClose(FileOpen($sFile, 2 + 8)) Local $hfOpen = FileOpen($sFile, 1 + 8) FileWrite($hfOpen, "UTF8 to ANSI") FileClose($hfOpen) i try this but after FileWrite the new file is still on utf8 Link to comment Share on other sites More sharing options...
Trong Posted March 3, 2015 Share Posted March 3, 2015 >#10 Regards, Link to comment Share on other sites More sharing options...
shai Posted March 3, 2015 Author Share Posted March 3, 2015 (edited) i create this function: Func utf8towindows1255($hFileorg, $hFiledest) Local $hFileOpen = FileOpen($hFileorg, 0) Local $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) FileClose(FileOpen($hFiledest, 2 + 8)) Local $hfOpen = FileOpen($hFiledest, 1 + 8) FileWrite($hfOpen, $sFileRead) FileClose($hfOpen) EndFunc and i run it on file that is encode in utf8. if i run it in my full script the output file is in utf8 but if i run it on new script with only this function the output file is in ANSI. why? Edited March 3, 2015 by shai Link to comment Share on other sites More sharing options...
Trong Posted March 4, 2015 Share Posted March 4, 2015 Your OS Version? XP/7/8/10/x32/x64 ? Your OS Language? English/China? Your AutoIt Version? 3.3.6.1/3.3.8.1/3.3.10.2/3.3.12.0/3.3.13.19/AutoitCN-3.3.9.21 ? It worked fine. MsgBox(0,"","File Encoding is: "&utf8towindows1255("UTFFile.txt", "ansi.txt")) Func utf8towindows1255($hFileorg, $hFiledest) Local $hFileOpen = FileOpen($hFileorg, 0) Local $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) FileClose(FileOpen($hFiledest, 2 + 8)) Local $hfOpen = FileOpen($hFiledest, 1 + 8) FileWrite($hfOpen, $sFileRead) FileClose($hfOpen) Return _GetFileEncoding($hFiledest) EndFunc ; * -----:| Func _GetFileEncoding($sFile) ; /*********************************************************************** * Trong ; * ---:| Function......: _GetFileEncoding($sFile) ; * ---:| Description...: Get File Encoding! ; ************************************************************************ * Local $sEndoding = FileGetEncoding($sFile), $sEncode $sEncode = $sEndoding If $sEndoding = 0 Then $sEndoding = "ANSI" If $sEndoding = 32 Then $sEndoding = "UTF16 Little Endian" If $sEndoding = 64 Then $sEndoding = "UTF16 Big Endian" If $sEndoding = 128 Then $sEndoding = "UTF8 (with BOM)" If $sEndoding = 256 Then $sEndoding = "UTF8 (without BOM)" If $sEndoding = -1 Then SetError(1, 0, -1) Return SetError(0, $sEncode, $sEndoding) EndFunc ;==>_GetFileEncoding Regards, Link to comment Share on other sites More sharing options...
AlienStar Posted November 21, 2017 Share Posted November 21, 2017 (edited) On 3/1/2015 at 8:55 PM, VIP said: a/ă expandcollapse popupLocal $sFile = "FileToCheckEncoding.txt" Local $hfOpen = FileOpen($sFile, 2 + 8) FileWrite($hfOpen, "Đào Van Trong") ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF) $hfOpen = FileOpen($sFile, 2 + 8 + 32) FileWrite($hfOpen, "UTF16 Little Endian: Đào Văn Trong") ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF) $hfOpen = FileOpen($sFile, 2 + 8 + 64) FileWrite($hfOpen, "UTF16 Big Endian: Đào Văn Trong") ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF) $hfOpen = FileOpen($sFile, 2 + 8 + 128) FileWrite($hfOpen, "UTF8 (with BOM): Đào Văn Trong") ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF) $hfOpen = FileOpen($sFile, 2 + 8 + 256) FileWrite($hfOpen, "UTF8 (without BOM): Đào Văn Trong") ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF) ; * -----:| Func _GetFileEncoding($sFile) ; /*********************************************************************** * Trong ; * ---:| Function......: _GetFileEncoding($sFile) ; * ---:| Description...: Get File Encoding! ; ************************************************************************ * Local $sEndoding = FileGetEncoding($sFile), $sEncode $sEncode = $sEndoding If $sEndoding = 0 Then $sEndoding = "ANSI" If $sEndoding = 32 Then $sEndoding = "UTF16 Little Endian" If $sEndoding = 64 Then $sEndoding = "UTF16 Big Endian" If $sEndoding = 128 Then $sEndoding = "UTF8 (with BOM)" If $sEndoding = 256 Then $sEndoding = "UTF8 (without BOM)" If $sEndoding = -1 Then SetError(1, 0, -1) Return SetError(0, $sEncode, $sEndoding) EndFunc ;==>_GetFileEncoding ; * -----:| Edit: In Notepad++ it works fine but I wanna set ini file in "UTF8 (without BOM)" encoding but after I use iniwrite it backs as "ANSI" !!!!!!! $hfOpen = FileOpen($sFile, 2 + 8 + 256) iniWrite($sfile, "General", "Title", "AutoIt") ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF) output: Encoding of file FileToCheckEncoding.txt is: ANSI - 0 please help Edited November 21, 2017 by AlienStar Link to comment Share on other sites More sharing options...
Trong Posted November 22, 2017 Share Posted November 22, 2017 INI files by design are not Unicode compatible. There are workarounds to get them to be able to utilize Unicode characters, but it's non-standard to use them with Unicode characters. So what you need to do is encode your section, key and value strings in UTF-8 and store that as if it was ANSI. That can't make the standard function behave strangely UNLESS you share this ini file with application not aware that sections, keys and values actually are UTF-8. Note that the ini file is itself an ANSI file (no UTF-8 BOM). jchd: Here's the secret sauce behind the hood: Local $sText = "中國 한국어 ไทย" Local $sUTF8 = BinaryToString(StringToBinary($sText, 4), 1) IniWrite("my.ini", "test", "key", $sUTF8) Local $sRaw = IniRead("my.ini", "test", "key", "I'm not there") Local $sValue = BinaryToString(StringToBinary($sRaw, 1), 4) MsgBox(0, "Round-trip check", $sValue) Regards, Link to comment Share on other sites More sharing options...
Velislav Posted November 7, 2019 Share Posted November 7, 2019 Hi! I know this topic is a bit old, but after I tried almost everything and nothing didn't work out for me I feel obligated to share with you the answer i found working perfect for me. The trick is to create a txt file with ANSI encoding and store it somewhere. Then whenever you want to create an ANSI encoding file just copy the txt file with the ANSI encoding where you want to have a txt ansi encoding file and then just write lines in it and there you go You are all set! MsgBox("","",FileGetEncoding("D:\.....template ANSI file path.....\UTD62_2019_ansi.txt")) FileCopy("D:\.....template ANSI file path.....\UTD62_2019_ansi.txt","D:\.....where you want ansi file path.....\UTD62_2019_304_ansi.txt") sleep(1000) MsgBox("","",FileGetEncoding("D:\.....where you want ansi file path.....\UTD62_2019_304_ansi.txt")) I hope this will help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now