您现在的位置是:网站首页> 编程资料编程资料
VBS和bat批处理逐行读取文件实例_DOS/BAT_
2023-05-25
342人已围观
简介 VBS和bat批处理逐行读取文件实例_DOS/BAT_
首先是批处理的,很简单,每隔两秒钟读取一行。
复制代码 代码如下:
@echo off
for /f "tokens=*" %%i in (lrbf.ini) do (echo %%i & ping -n 2 127.1>nul)
pause
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 后面是你发挥的地方
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
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
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
您可能感兴趣的文章:
相关内容
- 使用bat批处理来安装和卸载ASP组件_DOS/BAT_
- bat批处理一键登录网易163和126邮箱_DOS/BAT_
- bat批处理彻底隐藏文件的方法(使用虚拟磁盘实现)_DOS/BAT_
- bat批处理彻底删除0KB顽固文件或文件夹的方法_DOS/BAT_
- bat批处理批量修改文件扩展名的方法_DOS/BAT_
- Windows运行bat批处理文件时隐藏cmd命令提示符窗口的方法_DOS/BAT_
- 实现Win7系统快速一键切换用户的bat脚本_DOS/BAT_
- BAT批处理判断IP地址并自动禁用启用网卡_DOS/BAT_
- 建立隐藏磁盘的bat代码_DOS/BAT_
- 利用DOS命令来对抗U盘病毒保护U盘数据_DOS/BAT_
