vbs读取ini文件中特定section下某keyName的value值

本人刚刚学习VBS,记录学习过程中遇到的问题及其解决方法(网搜or自写),希望能帮助到其他伙伴。

REM getOperationType
REM iniPath is the path of ini file that you want to read
REM sectionName and keyName which are the keyName you want to find in the sectionName
Function getOperationType(iniPath , sectionName ,keyName)
  Const ForReading = 1
  Dim fso , objFile ,textLine , tmpArray
  Dim operationType : operationType = "Not Found"
  Dim status:status = 0
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set objFile = fso.OpenTextFile(iniPath , ForReading)

  REM AtEndOfStream is available for only-read TextFile
  Do Until objFile.AtEndOfStream
    REM Every execution,textFile.readline reads the new line
    textLine = objFile.readline
    REM status indicates you find the sectionName, then begin to find the keyName under it
    If InStr(textLine , sectionName) <> 0 And InStr(textLine , "[") And InStr(textLine , "]") <> 0 Then
      status = 1
    End If
    If status = 1 Then
      If InStr(textLine , keyName) <> 0 Then
        tmpArray = Split(textLine , "=" , -1 , 1)
        operationType = Lcase(Trim(tmpArray(1)))
        Exit Do
      End If
    End If
  Loop
  objFile.close
  getOperationType = operationType
  Set objFile = Nothing
  Set fso = Nothing
End Function

 

转载于:https://www.cnblogs.com/huihui1989/p/3672542.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值