Question

I am looking to read a txt file and then be able to use that variable in my vb script, but it is not working. if I echo it out to console, it puts out "ÿþH". I do not know what this is. here is my code

Const FONTS = &H14&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FONTS)


FileName = "c:\users\user\desktop\fonts.txt"
Const ForReading = 1
Set objFile = fso.OpenTextFile(FileName, ForReading)
Do Until objFile.AtEndOfStream
  count = objFile.ReadLine
  Wscript.Echo count    'this outputs "ÿþH" instead of "arial.ttf" from file
  objFoler.CopyHere "c:\users\user\desktop\"& count
Loop
objFile.Close
Was it helpful?

Solution

The file is probably Unicode, not ASCII.

If you add Const TristateTrue = -1 to your script, and then call Set objFile = fso.OpenTextFile(FileName, ForReading, TristateTrue) instead of Set objFile = fso.OpenTextFile(FileName, ForReading), the file will be opened as Unicode instead of ASCII.

According to the documentation for Scripting.FileSystemObject, the TristateTrue means the file will be opened as Unicode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top