2011年11月12日 星期六

read a file

Here is the code:


Option Explicit

Dim objFSO, strTextFile, strData, strLine, arrLines
CONST ForReading = 1

'name of the text file
strTextFile = "textfile.conf"

'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

'Step through the lines
For Each strLine in arrLines
wscript.echo strLine
Next

'Cleanup
Set objFSO = Nothing
http://hacktivision.com/index.php/2009/04/24/vbscript-to-read-a-text-file-line-by-lin?blog=2

沒有留言: