Sign in to follow this  
Followers 0
Michel Claveau

How to force FileRead read UTF-16? (Solved)

8 posts in this topic

#1 ·  Posted (edited)

Hi!

This windows/console command:

CMD /U /C DIR *.jpg > listdir.txt
give a file, in UTF-16. But this file has no "Unicode-UTF16 header".

FileRead don't open the file with UTF-16 decoding.

Any idea, for force FileRead to use UTF-16?

Thanks in advance.

Edited by Michel Claveau

Share this post


Link to post
Share on other sites



Take a look at the mode parameters for FileOpen() in the help file. You can force the file to open in UTF-16 before you read it.


Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

Hi!

Take a look at the mode parameters for FileOpen() in the help file. You can force the file to open in UTF-16 before you read it.

Thank you, but (Aaaarrrrggghh!!!) this parameter is only for Writing, and don't run for reading.

Share this post


Link to post
Share on other sites

Hi!

Thank you, but (Aaaarrrrggghh!!!) this parameter is only for Writing, and don't run for reading.

Sorry, I must've overlooked that. However, from the help file entry for FileRead():

Both ANSI and UTF16/UTF8 text formats can be read - AutoIt will automatically determine the type.


Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

re-Hi!

AutoIt will automatically determine the type.

OK, but for that, AutoIt use the "Unicode-header" (FF-FE or FE-FF, for UTF-16). Unfortunately, sometimes, this information is missing, as in the case that I gave.

That is why I try to "force" the mode of reading in Autoit.

Share this post


Link to post
Share on other sites

how about FileOpen, view as hex, add the header, save and now open?

I know it might sound stupid and I'm not even sure if it will work but that's the only way I could think about.

Share this post


Link to post
Share on other sites

Hi!

how about FileOpen, view as hex, add the header, save and now open?

I know it might sound stupid and I'm not even sure if it will work but that's the only way I could think about.

I reached the same conclusion.

Too bad we can not force the encoding FileRead :-(

Share this post


Link to post
Share on other sites

Hi, all!

I found!

Look this example:

$data = BinaryToString(FileRead($myfile),2)

@+

--

MCI

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