Function ReadTxt(pathway)
Dim fso,myfile,i
'Dim ReadLine(10)
Set fso=CreateObject("Scripting.FileSystemObject")
If fso.FileExists(pathway) Then
Set myfile=fso.OpenTextFile(pathway,1,False)
Else
WScript.Echo "该文档不存在"
End If
i=0
If Not myfile.AtEndOfStream Then
While Not myfile.AtEndOfLine
'ReadLine(i)=myfile.ReadLine()
'ReadLine=ReadLine&" "&myfile.ReadLine()'将所有行数据合在一起
ReadLine=myfile.ReadAll()
Wend
Else
ReadLine="文件内容为空"
End If
myfile.Close()
WScript.Echo ReadLine
End Function
'逐行写入文本数据
Function WriteTxt(pathway,content)
Dim fso,myfile
Set fso=CreateObject("Scripting.FileSystemObject")
ON Error Resume Next
If Not fso.FileExists(pathway) Then
fso.CreateTextFile(pathway)
End If
Set myfile=fso.OpenTextFile(pathway,8,True)
myfile.WriteLine(content)
myfile.Close()
If Err.Number<>0 Then
WScript.Echo Err.Number&Err.Description&" "&Err.Source
End if
End Function
'调用读写函数
Call WriteTxt("C:\Documents and Settings\Administrator\桌面\3.txt","hoho,写入数据测试")
Call ReadTxt("C:\Documents and Settings\Administrator\桌面\3.txt")