Write UTF8 text file with BOM from script?

How to change this code to use UTF8 with BOM to write to the file?

I'm trying to learn Dopus to replace other software, thanks for your help!

// STEP 6: Write the TagLines array to the ADS tag file.
      if (nTag < nTagNames || oFSO.FileExists (sTagFile)) { // Exclude another trivial case.
        var oFileWrite = oFSO.OpenTextFile (sTagFile, 2, true) // Create if missing.
        for (nn = 0; nn < nTagNames; nn++) {
           DOpus.Output (aTagLines [nn])
           oFileWrite.WriteLine (aTagLines [nn])
        }
        oFileWrite.Close ()

Add multiple filters and tags to files using ADS - Buttons/Scripts - Directory Opus Resource Centre (dopus.com)

FileSystemObject.OpenTextFile is a Microsoft-provided method, and while it has a Unicode option, it will result in a UTF-16 file not a UTF-8 file.

If you use the Directory Opus File object instead of Microsoft's one, that will write text to the file as UTF-8 by default.

(If you need a BOM, you may need to write one to the start of the file explicitly, although I'm not sure.)

Opus also provides the StringTools object, which can convert text between different encodings, but you probably won't need to use that here.


It's also worth having a read of the Editing & Formatting Tips link above the post editor, to learn how to post code blocks and other useful things:

2022-08-10 14-07-42 Clipboard Image

I need UTF8 with BOM, I searched and found some code but not working, I don't know yet, can you show me some code?

Have you tried using the File object as I suggested? Please show the test code.

If you want us to write code for you, please link your account.