Jump to content
Sign in to follow this  

FileWrite Issue with UTF8

Recommended Posts

Hey all,

Ive got an issue writing to a UTF8NOBOM file.

my code is below, its succesful on opening and closing the file, but it fails to write to it despite using '$FO_UTF8_NOBOM (256) = Use Unicode UTF8 (without BOM) reading and writing mode.'

I have also tried: $FO_APPEND + $FO_UTF8_NOBOM which does not change the line in the file, and $FO_OVERWRITE  + $FO_UTF8_NOBOM which just leaves me with a blank file

Anyone got any ideas?

#include <File.au3>

$File = "C:\file.m"
$filehandle = FileOpen($File, $FO_UTF8_NOBOM)
        $FileContent = FileRead($filehandle, -1)
        $Find = "DO NOT USE"
        $Replace = "This Should Never Be Used"
        $filehandle = FileOpen($File, $FO_UTF8_NOBOM)
        $FileContent = StringReplace($FileContent, $Find, $Replace)
        $A = FileWrite($filehandle, $FileContent)
        $B = FileClose($filehandle)
Msgbox (4096, "QA", $filehandle & @crlf & $A & @crlf & $B)
Edited by cookiemonster

Share this post

Link to post
Share on other sites

Default is read mode so what you have now is read as $FO_UTF8_NOBOM+$FO_READ. You must add $FO_APPEND or $FO_OVERWRITE

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  

  • Create New...