In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "VBS how to read configuration file configuration items", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "VBS how to read configuration file configuration items" this article.
The following is a function to read the configuration file: this function applies only to configuration files in the following formats (.ini, .txt, .inf):
[Mark1] key1=key1valuekey2= key2value.[Mark2] key1=key1valuekey2=key2value
Core code
'* *' function: read the value of the configuration item in the configuration file (.ini, .txt format) And return the value 'parameter: FilePath-the full path to the configuration file' Mark-configuration start tag 'Key-the name of the configuration item to be obtained' call method: Ret = GetConfig ("d:\ configure.ini", "Computer") "IP") 'author: Tiger Shaw Supreme' date: 2013-06-20'***Function GetConfig (FilePath,Mark,Key) Dim fso Str_ReadLine Set fso = CreateObject ("Scripting.FileSystemObject") 'determines whether the If fso.FileExists (FilePath) Then' initialization configuration flag exists in the configuration file. Default is Flag = 0 'Open configuration file Set ConfigFile = fso.opentextfile (FilePath) 1) 'Loop read file data line Do Str_ReadLine = ConfigFile.ReadLine WScript.Echo Str_ReadLine' to determine whether the read data line is empty If Str_ReadLine "" Then "determine whether the read data line is the configuration start tag If LCase (Trim (Str_ReadLine)) =" ["& Lcase (Mark) &"] "Then 'find the configuration start tag Flag = 1' cycle read the configuration item under the current configuration start tag Exit Do Str_ReadLine = ConfigFile.ReadLine retNum = InStr (Str_ReadLine, "=") 'until the desired configuration item is found under the current configuration tag or when the next configuration item opening tag appears. Check whether the read configuration item has an equal sign If retNum > 0 configuration' to determine whether the name of the acquired configuration item is the desired configuration item If Trim (LCase (Left (configuration)). (retNum-1)) = Trim (LCase (Key)) Then 'get the data after the equal sign of the configuration item GetConfig = Trim (Right (Str_ReadLine,Len (Str_ReadLine)-retNum))', exit the function Exit Function End If End If'to determine whether the next configuration item is currently marked If (InStr (Str_ReadLine, "[") > 0 And InStr (Str_ReadLine) "]") > 0) Then 'marks the beginning of the current configuration item as the next configuration Flag = 0' exit function Exit Function End If Loop Until (Flag = 0 Or ConfigFile.AtEndOfStream) End If End If Loop Until ConfigFile.AtEndOfStream 'close file ConfigFile.Close Set fso = Nothing Else' file not found, give a message MsgBox "configuration file" & "[" & FilePath & "] does not exist, please check whether the path is correct." End IfEnd Function
Example:
We need to read the value of the IP entry under [Computer2] in the d:\ config\ environment.ini file, which is as follows:
[Computer1] ComputerName=Computer1IP= 192.168.1.1[Computer2] ComputerName=Computer2IP=192.168.1.2
Use the above function to get the
IP = GetConfig ("d:\ config\ environment.ini", "Computer2", "IP") Msgbox IP
These are all the contents of the article "how VBS reads configuration items in configuration files". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.