0

I'm trying to save the output text file from this vbscript as ANSI instead of Unicode.

This is the simplified script:

Option Explicit

dim fso, obs, fol, spl, files, objFile, arr, file, ext, ex
Set fso = CreateObject("scripting.filesystemobject")
Set obs = CreateObject("shell.application")
Set fol = fso.GetFolder(".")
Set spl = obs.NameSpace(fol.Path)
Set files = fol.Files
set objFile = fso.openTextFile("test.txt" ,2 , true, false)
arr = Array("mp4")

For Each file In files
    ext = fso.GetExtensionName(file.Name)
    For Each ex In arr
        If StrComp(ext,ex,1)=0 Then
            objFile.writeline fol.Path & "\" & spl.GetDetailsOf(spl.ParseName(file.Name),0) & vbcrlf & spl.GetDetailsOf(spl.ParseName(file.Name),27) & vbcrlf & spl.GetDetailsOf(spl.ParseName(file.Name),28)
        End If         
    Next
Next
objFile.Close

If I change:

set objFile = fso.openTextFile("test.txt" ,2 , true, false)

To:

set objFile = fso.openTextFile("test.txt" ,2 , true, true)

the script works, but saves the output as Unicode. If I keep the false the script gives me Invalid procedure call or argument. This is the part that is causing the error:

spl.GetDetailsOf(spl.ParseName(file.Name),28)

I have tried loads of other extended properties and they all work fine as ANSI. It just seems to be this one that is giving me problems. I have tried loads of different files and the result is the same. I don't know enough to fix this unfortunately, so I would be very greatful for any help.

Greg M
  • 140
  • 1
  • 11
  • Are you sure that the details (GetDetailsOf) which you are writing (WriteLine) doesn't have any Unicode values in it? – Pankaj Jaju Dec 04 '17 at 12:10
  • All of the ones I tried work fine except for (28) Which on windows 7 is Bit Rate. The result I get in Unicode is 191kbps as an example. If I manually change the output file to ANSI I does tell me it contains Unicode characters. I just tried deleting the bit rate lines out of the output file and it still says the same thing. I've been trying for hours now. I don't know what else to try. – Greg M Dec 04 '17 at 12:25

1 Answers1

1

The probable reason for your problem is explained here. The 28/Bitrate detail/property may contain a Left-To-Right-Mark. The remedy is to .WriteLine Mid(spl.GetDetailsOf(spl.ParseName(file.Name),28), 2) to the file.

Of course, if other data contain non-ANSI characters, you need to sanitize it accordingly.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96