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

Wondering who uses AutoIT and what it can be used for ?

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: 2017-05-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.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF * GitHub API UDF - modest begining *

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 * _IEquerySelectorAll() (by uncommon) * 

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

    • chacoya121
      By chacoya121
      Local $count = 1 Local $x1= 100,$y1 = 100,$x2 = 110,$y2 = 110 $area = ($x2+$x1)*($y2+$y1) Local $array[$area][2] For $i = $x1 to $x2 Step 1 For $j = $y1 to $y2 Step 1 $color = PixelGetColor($i,$j) $scolor = Hex($color,6) $array[$count][2] = [$scolor,1] $position = _ArraySearch($array,$scolor,0,0,0,0,1) If $array[$position][0] = $scolor Then $array[$position][1] +=1 Else $count += 1 EndIf Next Next _ArrayDisplay($array) plz help adjust and shrink it down soo confusing playing with array
    • virhonestum
      By virhonestum
      I've coma accross a very odd problem. I want to download a CSV-File, and process the contents.
      This is the extremely simplyfied AutoIT-Code, given the file is already downloaded:
      $f= @ScriptDir & "\TestFile.csv" $file = FileOpen($f,0) Local $line = FileReadLine($file) MsgBox(0,"",$line) The downloaded CSV file I want to process contains something like this:
      Artikelnummer;EAN-Code;Artikelname;Artikelgewicht;Beschreibung;Kurzbeschreibung;Eigenschaften;Technische-Daten;Bild1;Bild2;Bild3;Bild4;Bild5;Bild6;Bild7;Bild8;Lieferbar;"Lieferbar Ab";Versandzeit;"UVP-Preis inkl. MwSt.";"Preis1";"Preis2";Hersteller L7335272;5420025602129; Mini Light XLR ;0.1000; JB Systems Schwanenhalsleuchte mit XLR Anschluss. ;;;;;;;;;;;;JA;; 1-3 Tage ;12,90;12,90;6,57; JB Systems L3320502;540207025601636; Mini Light LED BNC ;0.1000; JB Systems LED Schwanenhalsleuchte mit BNC Anschluss. ;;;;;;;;;;;;JA;; 1-3 Tage ;29,90;25,89;15,26; JB Systems L1332254;542002556023143; Mini Light LED XLR ;0.1000; JB Systems LED Schwanenhalsleuchte mit XLR Anschluss. ;;;;;;;;;;;;JA;; 1-3 Tage ;29,90;25,89;15,26; JB Systems L8302591;504200256280277; Spiegelkugel 10cm ;0.5000; JB Systems Spiegelkugel 10cm Durchmesser mit einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;;;;;;;;;JA;; 1-3 Tage ;5,50;4,90;2,81; JB Systems L7302932;542000256510222; Spiegelkugel 20cm ;0.8400; JB Systems Spiegelkugel 20cm Durchmesser mit einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;;;;;;;;;JA;; 1-3 Tage ;12,90;11,50;6,58; JB Systems L2350293;534200562064239; Spiegelkugel 30cm ;2.1300; JB Systems Spiegelkugel 30 cm Durchmesser mit einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;;;;;;;;;JA;; 1-3 Tage ;26,90;23,00;13,72; JB Systems L3302984;545200252024246; Spiegelkugel 40cm ;3.5000; JB Systems Spiegelkugel 40cm Durchmesser mit Sicherungsring und einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;;;;;;;;;JA;; 1-3 Tage ;54,90;49,00;28,00; JB Systems L9302495;542205056225600; Spiegelkugel 50cm ;5.3900; JB Systems Spiegelkugel 50cm Durchmesser mit Sicherungsring und einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;;;;;;;;;JA;; 1-3 Tage ;89,00;79,00;45,39; JB Systems But the message box that pops up after FileReadLine contains this:
      䅲瑩步汮畭浥爻䕁中䍯摥㭁牴楫敬湡浥㭁牴楫敬来睩捨琻䉥獣桲敩扵湧㭋畲穢敳捨牥楢畮朻䕩来湳捨慦瑥渻呥捨湩獣桥ⵄ慴敮㭂楬搱㭂楬搲㭂楬搳㭂楬搴㭂楬搵㭂楬搶㭂楬搷㭂楬搸㭌楥晥牢慲㬢䱩敦敲扡爠䅢∻噥牳慮摺敩琻≕噐ⵐ牥楳⁩湫氮⁍睓琮∻≐牥楳ㄢ㬢偲敩猲∻䡥牳瑥汬敲ੌ㜳㌵㈷㈻㔴㈰〲㔶〲ㄲ㤻M楮椠䱩杨琠塌刀㬰⸱〰〻J䈠卹獴敭猠卣桷慮敮桡汳汥畣桴攠浩琠塌删䅮獣桬畳献;㬻㭨瑴瀺⼯睷眮數慭灬攮捯洯浥摩愯業慧敳⽯牧⽰楣㈰〷〱ㄴㄵ㌵〰愮橰朻㬻㬻㬻㭊䄻㬀ㄭ㌠呡来;ㄲⰹ〻ㄲⰹ〻㘬㔷㬀䩂⁓祳瑥浳 I've attached both files I use. 
      My guess is, that there's something wrong with the encoding, but I'm not sure how to fix it.
      Thank you very much for your help
      - virhonestum
    • 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!