如何使用 VBScript 从文本文件中读取? [英] How to read from a text file using VBScript?
本文介绍了如何使用 VBScript 从文本文件中读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望看到一种使用 VBScript 读取和写入文本文件的简单方法.
I am looking to see a simple way to read from and write to a text file using VBScript.
我认为这是写入文件的可接受方法.
I think this is an acceptable method for writing to a file.
Dim f,
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateTextFile("C:\test.txt", True, True)
f.WriteLine("Data to Add to file.")
f.Close
但是,我想知道如何以类似的方式读取文件.
However, I would like to know how to read from a file in a similar fashion.
推荐答案
先使用方法 OpenTextFile
,然后...
Use first the method OpenTextFile
, and then...
要么使用 ReadAll
:
Set file = fso.OpenTextFile("C:\test.txt", 1)
content = file.ReadAll
或者一行一行的方法ReadLine
:
or line by line with the method ReadLine
:
Set dict = CreateObject("Scripting.Dictionary")
Set file = fso.OpenTextFile ("c:\test.txt", 1)
row = 0
Do Until file.AtEndOfStream
line = file.Readline
dict.Add row, line
row = row + 1
Loop
file.Close
'Loop over it
For Each line in dict.Items
WScript.Echo line
Next
这篇关于如何使用 VBScript 从文本文件中读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文