Sign in to follow this  
Followers 0
Fran

Convert file format from ANSI to UCS-2 Little Endian

6 posts in this topic

I need to find and replace some text in a text file, but the file is in UCS-2 Little Endian format, and after my script replaces the said text, the file format changes to ANSI.

Is there a way that I can convert the file back to UCS-2 Little Endian format after I've replaced the text?

Share this post


Link to post
Share on other sites



Just add BOM.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

I give up ;)

I have an ini file that I need to write to, but the ini file does not have sections and it is in format Little Endian.

Try as I may I cannot write to the file and keep the original format. It keeps going back to ANSI. And if I use FileOpen("",32), I can't figure out how to write over a specific line in the file. It keeps appending my text to the end of the file.

Either I'm missing something or what I'm trying to accomplish is close to impossible.

Hope you can help me.

F

Share this post


Link to post
Share on other sites

Either I'm missing something or what I'm trying to accomplish is close to impossible.

It's that first part.

Your code?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

I think I got it... give me a few minutes and I'll post the script so you can double check it for me.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This seems to do the trick. Might be a bit of a roundabout way though...

(and I still need to clean up the code a bit)

Any comments?

The reason why I use FileInstall is because in the original ini on the user's computer, there is no [] and I haven't found a way to write the [] into the top of the file without converting it back to ANSI.

So the file I'm "installing" already includes the [] and it's in the correct format.

#include <Constants.au3>
#include <File.au3>

FileCopy("C:\Program Files\RapidStudio\MPR500 Pro 5\AlbumMaker.ini", @TempDir & "\AlbumMaker_orig.ini")
$iniOrig = @TempDir & "\AlbumMaker_orig.ini"
_FileWriteToLine($iniOrig,1,"[]",0)
$baseFolder = IniRead($iniOrig,"","BASE_FOLDER","C:\MPR500_Resources")
$submitFolder = IniRead($iniOrig,"","BASE_SUBMIT_FOLDER","C:\RapidStudio_Submitted_Orders")
MsgBox(4096,"Result",$baseFolder & @CRLF & $submitFolder)
FileInstall("\SDK\AlbumMaker.ini","C:\Program Files\RapidStudio\MPR500 Pro 5\",1)

Const $iniNEW = "C:\Program Files\RapidStudio\MPR500 Pro 5\AlbumMaker.ini"
$encoding = FileGetEncoding($iniNEW)
MsgBox(0,"","File initial encoding = " & $encoding)
$file = FileOpen($iniNEW,32)
;check if file opens ok
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

IniWrite($iniNEW,"","BASE_FOLDER"," " & $baseFolder)
IniWrite($iniNEW,"","BASE_SUBMIT_FOLDER"," " & $submitFolder)
IniWrite($iniNEW,"","ORDER_SKD"," 1")

FileClose($file)
FileFlush($file)
$encodingClose = FileGetEncoding($iniNEW)
MsgBox(0,"","File encoding after writing = " & $encodingClose )
FileDelete($iniOrig)
Edited by Fran

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
Sign in to follow this  
Followers 0