leuce Posted October 28, 2008 Share Posted October 28, 2008 G'day everyoneI'm just sharing my method of adding a BOM to UTF8 files that don't have them. I often deal with files from Linux people and them Linux folks just don't know what a BOM is for. Anyway, enough talk.expandcollapse popup; File without BOM is foo.txt ; New file with BOM is foo2.txt $fileopen = FileOpen ("foo.txt", 16) $fileread = FileRead ($fileopen) FileClose ($fileopen) $newfile = FileOpen ("foo2.txt", 18) $bin = StringToBinary("") FileWrite ($newfile, $bin & $fileread) FileClose ($newfile) ; == ; File without BOM is foo.txt ; New file with BOM is also foo.txt $fileopen = FileOpen ("foo.txt", 16) $fileread = FileRead ($fileopen) FileClose ($fileopen) $newfile = FileOpen ("foo.txt", 18) $bin = StringToBinary("") FileWrite ($newfile, $bin & $fileread) FileClose ($newfile) ; == ; File without BOM is foo.txt ; File without BOM is backed up ; New file with BOM is also foo.txt $foofile = "foo.txt" $fileopen = FileOpen ("foo.txt", 16) $fileread = FileRead ($fileopen) FileClose ($fileopen) $backup = FileOpen ("backup_" & $foofile, 18) FileWrite ($backup, $fileread) FileClose ($backup) $newfile = FileOpen ("foo.txt", 18) $bin = StringToBinary("") FileWrite ($newfile, $bin & $fileread) FileClose ($newfile)Not very fancy but useful to have somewhere when you want to paste it in a new script.I haven't figured out how to check if a file has a BOM or not, though. I mean, I have a way to do it but it involves using additional tools. It would be cool to be able to check a file for a BOM using only AutoIt.Samuel(and just to show that I'm a real newbie: http://leuce.com/tempfile/omtautoit/ ) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now