SoFunction
Updated on 2025-04-10

VBS and bat batch reading file instances line by line

First of all, it is batch processing, it is very simple, reading a line every two seconds.

Copy the codeThe code is as follows:
@echo off
for /f "tokens=*" %%i in () do (echo %%i & ping -n 2 127.1>nul)
pause

More intuitive:

Copy the codeThe code is as follows:
FOR /F "delims=" %i IN () DO echo %i

Of course if you want to do more other things do is where you play

Two versions of VBS

The first method is to read line by line and display it in sequence:

Copy the codeThe code is as follows:
Const ForReading = 1
dim   objFSO,objFile,strline  
Set objFSO = CreateObject("")
Set objFile = ("", ForReading)
do   until     
        strline=  
strline   'This is just a line of content that can be replaced with other content
loop  
  
set   fso=nothing

The second method is to read all and display it in turn:
Copy the codeThe code is as follows:
Const ForReading = 1
dim   objFSO,objFile,strline  
Set objFSO = CreateObject("")
Set objFile = ("", ForReading)
str=  
  
if   str=""   then  
           "Nothing"  
          
end   if  
strarry=split(str,vbcrlf)  
for   each   linestr   in   strarry  
linestr   'Here is the content of each line that can be replaced with other content
next  
set   fso=nothing 

VBS reads the last line of text:
Const ForReading = 1
Set objFSO = CreateObject("")
Set objFile = ("", ForReading)
Do Until
strNextLine =
If Len(strNextLine) > 0 Then
strLine = strNextLine
End If
Loop

strLine