windows-scripting

"Object required" - path string unrecognized in windows scripting file


I'm writing a wsf that opens a csv, reads the contents and prints them like so:

<job id="Test_Script">
   <script language="VBScript">

    Dim objFSO, strSourcePath, strSourceFile, objInFile, strData    

    Set strSourcePath = "C:\test\ERACSV\"
    Set strSourceFile = "Payments.csv"
    Set objFSO        = CreateObject("Scripting.FileSystemObject")   
    Set objInFile     = objFSO.OpenTextFile(strSourcePath & strSourceFile, 1, False)
    Set strData       = objInFile.ReadAll
    objInFile.Close

    WScript.Echo strData
   </script>
</job>

I keep getting this weird error:

Script:  C:\Users\myuser\openCSV.wsf
Line:    4
Char:    4
Error:   Object Required '[string: "C:\test\ERACSV"]'
Code:    800A01A8
Source:  Microsoft VBScript runtime error

It seems weird because why is the object it requiring a string I've already defined?


Solution

  • <job id="Test_Script">
       <script language="VBScript">
    
        Option Explicit
    
        Dim objFSO, strSourcePath, strSourceFile, objInFile, strData    
    
        Let strSourcePath = "C:\test\ERACSV\"
        Let strSourceFile = "Payments.csv"
        Set objFSO        = CreateObject("Scripting.FileSystemObject")   
        Set objInFile     = objFSO.OpenTextFile(strSourcePath & strSourceFile, ForReading, False)
        Let strData       = objInFile.ReadAll()
        objInFile.Close
    
        WScript.Echo strData
       </script>
    </job>