@echo off
for /f "tokens=*" %%i in (lrbf.ini) do (echo %%i & ping -n 2 127.1>nul)
pause
更直觀的:
代碼如下:
FOR /F "delims=" %i IN (file.txt) DO echo %i
當然如果你想做更多其他的事 do 后面是你發(fā)揮的地方
VBS的兩個版本
第一種方式,逐行讀取,依次顯示:
代碼如下:
Const ForReading = 1
dim objFSO,objFile,strline
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("lrbf.ini", ForReading)
do until objFile.atendofstream
strline=objFile.readline
wscript.echo strline '這里是顯示一行內容而已,可以換成別的內容
loop
objFile.close
set fso=nothing
第二種方式,全部讀取,依次顯示:
代碼如下:
Const ForReading = 1
dim objFSO,objFile,strline
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("lrbf.ini", ForReading)
str=objFile.readall
objFile.close
if str="" then
wscript.echo "Nothing"
wscript.quit
end if
strarry=split(str,vbcrlf)
for each linestr in strarry
wscript.echo linestr '這里是用echo顯示每一行的內容,可以換成別的內容
next
set fso=nothing
VBS讀取文本最后一行:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("lrbf.ini", ForReading)
Do Until objFile.AtEndOfStream
strNextLine = objFile.ReadLine
If Len(strNextLine) > 0 Then
strLine = strNextLine
End If
Loop
objFile.Close
Wscript.Echo strLine
更多信息請查看IT技術專欄