Save txt file with ISO 8859-1 encoding

3 posts in this topic


I need to save a file with ISO 8859-1 encoding

Now my script is:

$contenuti_header = "Configuration file  <>  O:\test.txt  <>  Last update: 28/09/2015 09:46:36 ð ñ"
$record_part1 = "ò1ò0ò1òLayer_01ïï1ï0ï0ï0ï0ï0ï0ïï0ï255ï0ï0ï0ï255ï255ï125ï0ï0ï3ï0ï0ï0ï0ï0ï0ï0ï0ï0ï3ï150ï5ï102ï82ï10ï4ï0ï0ïTahoma;16777215;22;1;ï0ï0ï0ïïïï0ï0ï33ï500ï200ï4ï1ï720ï10ï5ï100ï63ï300ï850ï16777215ï0ï0ï0ï0ï0ï0ï0ï0ï0ï0ï"
$record_part2 ="ï0ïTahoma;16777215;22;1;ïïhh.nnïïï0ïï0ï0ï0ï4ï65793ï255ï0ï2ï0ï0ïï5ï5ï0ï0ï0ï0ï0ï100ï100ï0ï0ï8421504ï16777215ïïï0ï0ïïï0ï720ï576ï0ï0ï0ï0ï0ï0ï0ï0ï2ï0ï6ï0ï0ï1ï0ï1ï0ï0ïîò0ò0òòòòòòó"
for $i = 1 to $num
    $contenuti_record = $record_part1 & "ò" & $num & $record_part2
$contenuti_end = "òòòòòòòòòòòòòó"
$fileTemplate = FileOpen("O:\file.txt", 2)
FileWrite($fileTemplate, $contenuti_header&$contenuti_record&$contenuti_end)

Autoit writes the file with UTF-8 encoding but the programs that read that file can't read it correctly. If I open file.txt with SublimeText and save it with ISO 8859-1 encoding, the program works well





Share this post

Link to post
Share on other sites

Read HelpFile for:


Focus on second parameter I mean "mode".

Try to use each of them.


1 person likes this

ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:


Last update: 2016-12-23
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, The Art of Computer Programming
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."


Share this post

Link to post
Share on other sites


using the code:

$fileTemplate = FileOpen("O:\file.txt", 2+16)

the program can read the file!!!



Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • 4bst1n3nz
      By 4bst1n3nz
      i need to save files with ANSI-Encoding. Since Auto-It it doesn't work in any direction.
      I tried the following:
      #include <FileConstants.au3> FileDelete(@ScriptDir&"\Test.txt") $o = FileOpen(@ScriptDir&"\Test.txt", BitOR($FO_BINARY,$FO_ANSI,$FO_OVERWRITE)) FileWrite($o, "Test") FileClose($o) Or
      #include <FileConstants.au3> FileDelete(@ScriptDir&"\Test.txt") $o = FileOpen(@ScriptDir&"\Test.txt", 514) FileWrite($o, "Test") FileClose($o) Both create UTF-8 encoded files.
      What am i doing wrong?
      Thank you!
    • SalamanderSoup
      By SalamanderSoup
      I've created a simple script that opens the Snipping Tool; Selects the "Full Screen Snip" option; then closes the program, prompting a save.  What I can't figure is how to name the file using the system date and time.
      Can anyone help?
      Run(@WindowsDir & '\system32\SnippingTool.exe') AutoItSetOption('MouseCoordMode', 0) Sleep(1) $hWnd= WinWait("Snipping Tool", "ToolBarWindow32", 1) WinActive($hWnd) MouseClick('primary', 84, 48, 1, 0) MouseClick('primary', 84, 140, 1, 0) WinClose("[Class:Microsoft-Windows-Tablet-SnipperEditor]") ControlClick("Snipping Tool", "", "Button1")  
    • Razraal
      By Razraal
      Hey there folks!
      I have an array of DllStructs, created with the function DllStructCreate. Let's call the array $structs. This $structs contains important information for the program. I want to save my  $structs variable for future use in a file (i.e.: the user closes the program, opens it again and has the option to load a file). I want to load files which contain a $structs variable, and let the program work with this "loaded" variable. Questions:
      Since I have never done such a thing (saving/loading a file, possibly in a different format from txt or ini), I'd like to know:
      Is this possible? Is my only option to save my $structs in text format? That would require a function which receives a file and interprets the text it has, creating a new $structs with the info it's getting from the file. (I think this could lead to trouble) I'm worried about security. Since the program will be loading files, I don't want it to crash because the user decided to give it modified files. Is it possible to create a file that's readonly for the user? That would prevent some tampering with the file. From what I've been reading, I have several functions available for File management, namely FileOpen, FileRead and FileWrite. In a first glance, these appear to be the only functions I need. Do I need more?  
      Thank you for your time!
    • CSL
      By CSL
      I want to take a binary data from any source (string,number,files,etc..) and iterate over each X bits of it in a loop, say take bits 1-5, then 6-10, etc.. Then I want to convert these bits to their corresponding decimal value.
      but all the binary functions I found in autoit only work with full bytes, and do not let me get smaller sections of bits, like "BinaryMid()" that "Extracts a number of bytes from a binary variant"
      Can anyone tell me if this is possible to do and how? and also if there is a function to convert those bits to/from decimals?
      I'm not that familiar with dealing directly with binary, so any help or tips will be very appreciated
      I'm trying to make a function to encode/decode any given binary data into/from a given array of characters. just like Base64 but using different bases then [a-z A-Z 0-9 +/= ]. My approach currently is to figure out how many bits of binary I can encode with each character, read those bits and convert them to a decimal number, then I will use that number as an index and take the character at that index from the character array and add it to the result string.
      I'm aware that there may be some padding needed.
    • Seminko
      By Seminko
      Hey fellas,
      I'm pulling data from web with multiple languages. I get a lot of ü and other special characters which show correctly in Scite when I change the encoding.
      However, I need the special characters to be displayed in an array. For example I get ' ĂĽ ' in an array which should translate ' ü ' .
      How do I do this?