There are times when a programmer might need to search and read a text file when using VBScript. It is possible to do this task by accessing the Windows Script Host, through VBScript. This is in addition to taking advantage of and utilising the FileSystemObject.
- Skill level:
Other People Are Reading
Create a text file using the following name and location:
Open and run the Notepad program. Click the "Start" button in the Windows desktop, click "All Programs," then select "Accessories" and click on "Notepad."
Copy and Paste the following into Notepad:
Const conForReading = 1
Dim objFSO, objReadFile, contents
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReadFile = objFSO.OpenTextFile("C:\Temp\TextToRead.txt", 1, False)
'Read file contents
contents = objReadFile.ReadAll
Set objFSO = Nothing
Set objReadFile = Nothing
Click "File" and select "Save" in Notepad and exit the program.
Run the script by double-clicking on the ReadTextFile.vbs VBScript file.
Click the "OK" button in the "Windows Script Host" prompt. You can now search and read a text file with a VBSript.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for