网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 VBS和bat批处理逐行读取文件实例
范文
    @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 后面是你发挥的地方
    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
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/17 9:45:49