1

I try to make a script in VBScript for PowerAMC. And I've got an error.

I checked all elements to make a file with the content (XSD file):

private Sub writeInFile(pathFolder, pathFile, val)
  Output "WriteInFile["&pathFolder&pathFile&"]"
  Dim fso, MyFile
  Set fso = CreateObject("Scripting.FileSystemObject")

  Set MyFile = fso.CreateTextFile(pathFolder&pathFile, true)
  If (fso.FileExists(pathFolder&pathFile)) Then
    MyFile.WriteLine(val)
  Else
    ouput "File can't be create"
  End If

  MyFile.Close
  end Sub

And the file exists with good content, but if I try to read it with:

public Function readFile(path)
  'Declare variables
  Dim objFSO, objReadFile, contents

  'Set Objects
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objReadFile = objFSO.OpenTextFile(path, 1, false)

  'Read file contents
  contents = objReadFile.ReadAll

  'Close file
  objReadFile.close

  'Cleanup objects
  Set objFSO = Nothing
  Set objReadFile = Nothing

  readFile = contents
   End Function

I get that : "ÿþ<" for only content, but if I try to read a file that is not created by the previous function, it runs perfectly.

karel
  • 5,489
  • 46
  • 45
  • 50
pikameuh
  • 149
  • 1
  • 1
  • 12
  • 1
    You're probably trying to read an UTF-8 encoded file. Take a look at http://stackoverflow.com/a/13855268/4584335 – Rubik Mar 03 '15 at 11:18

1 Answers1

1

I think the problem comes from Unicode format, take a look at this => FileSystemObject - Reading Unicode Files

Community
  • 1
  • 1
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • I had solved the problem with : Set oReadfile = FS.OpenTextFile(sFile, 1, False, True) The true argument fixed the bug, THX ! – pikameuh Mar 03 '15 at 11:48