MattsBits
MattsBits

MattsBits

How To Read And Write Text Files Using VBScript  

by Matt Hawkins, 09/05/2009
Categories : VBScript

This example code shows how you can use VBScript to read and write standard text files. The code below can be used as a basis for reading lines from one file, processing them and then writing them back out to another file.

The example script can be used as a base for processing CSV, HTML and XML files.

To use the example paste the code into a text file and give it a .vbs extension.


Set oReadObj = CreateObject("Scripting.FileSystemObject")
Set oWriteObj = CreateObject("Scripting.FileSystemObject")

Set oRead = oReadObj.OpenTextFile("input.txt", 1)
Set oWrite = oWriteObj.CreateTextFile("output.txt", True)

Dim strLine
Dim intLineCounter

intLineCounter = 0

Do Until oRead.AtEndOfStream

strLine = oRead.ReadLine

' Process or modify the strLine variable here
' before it is written to the output file

oWrite.WriteLine(strLine)

intLineCounter = intLineCounter + 1

Loop

oWrite.Close() ' Close output file
oRead.Close() ' Close input file

msgbox("Script Finished")

Author : Matt Hawkins  Last Edit By : Matt Hawkins
PHP Powered  MySQL Powered  Valid XHTML 1.0  Valid CSS  Firefox - Take Back The Web  EUKHost - Recommended Webhosting Solutions

MattHawkins CMS v3.0 - Copyright 2009-2022