VBS and BAT Batches read file instances line by row _dos/bat

Source: Internet
Author: User
Tags readline

First, it's batch, and it's easy to read a row every two seconds.

Copy Code code as follows:
@echo off
for/f "tokens=*"%%i in (Lrbf.ini) do (Echo%%i & Ping-n 2 127.1>nul)
Pause

More intuitive:

Copy Code code as follows:
for/f "delims="%i in (file.txt) do Echo%i

Of course, if you want to do something else, do what's behind you.

Two versions of VBS

The first way, read-by-line, and then display:

Copy Code code as follows:
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 ' Here is a line of content that can be replaced with something else.
Loop
Objfile.close
Set fso=nothing

the second way, read all, and display in turn:
Copy Code code as follows:
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 ' Here is an echo showing the contents of each row, and can be replaced with something else.
Next
Set fso=nothing

VBS reads the last line of text:
Const ForReading = 1
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set objfile = objFSO.OpenTextFile ("Lrbf.ini", ForReading)
do Until
Objfile.atendofstream = strnextline Le. ReadLine
If Len (strnextline) > 0 Then
strLine = strnextline
End If
Loop
Objfile.close
WSCRIPT.E Cho strLine

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.