VBScript Basics, Part 20 | Read Files (OpenTextFile)


VBScripting (.vbs) Basic tutorial on how to use the OpenTextFile command to read a files contents.

Code Example:
______________________________________________________

Option Explicit
Dim fso, oFile, a
Set fso = CreateObject(“Scripting.FileSystemObject”)

Sub Refresh
Set oFile = fso.OpenTextFile(“C:UsersJeremyDesktopnew.txt”,1)
End Sub

Call Refresh
For a=1 to 2
msgbox oFile.ReadLine
Next

Call Refresh
msgbox oFile.ReadAll
______________________________________________________

Know the Basics:
——————————————————————————————
Set fso = CreateObject(“Scripting.FileSystemObject”)

Set x = fso.OpenTextFile(“FILE-LOCATION”,1)
x.Read(#) = read number of characters.
x.ReadLine = read lines.
x.ReadAll = read all of the file.
x.AtEndOfStream = check to see if file is at the end.
x.Close = close the command for reading.
——————————————————————————————



Leave a Comment