Board logo

标题: 新年快乐!VBS如何读取文本最后一行? [打印本页]

作者: hackhd     时间: 2008-2-6 01:24    标题: 新年快乐!VBS如何读取文本最后一行?
如题

作者: sonicandy     时间: 2008-2-6 09:00
新年快乐。
Set fso = createobject
("filesystemobject")
set stream = fso.opentextfile
("test.txt",1)
lines = stream.readall
call stream.close()
arr = split(lines,vbcrlf)
call msgbox(arr(ubound(arr)))

[[i] Last edited by sonicandy on 2008-2-6 at 09:04 AM [/i]]

作者: 3742668     时间: 2008-2-6 12:52

On Error Resume Next
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile("a.txt")
If Err Then
WScript.Echo Err.Description
Set oFSO = Nothing
WScript.Quit
End If

Do Until oFile.AtEndOfLine
str = oFile.ReadLine
Loop

WScript.Echo str
oFile.Close
Set oFile = Nothing
Set oFSO = Nothing

作者: lotus516     时间: 2008-2-6 20:41
Set objFSO = CreateObject("Scripting.FileSystemObject")  
Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", 1)
Do Until objFile.AtEndOfStream
strNextLine = objFile.ReadLine
If Len(strNextLine) > 0 Then
strLine = strNextLine
End If
Loop
objFile.Close
Wscript.Echo strLine


Last edited by lotus516 on 2008-2-10 at 06:01 PM ]