使用VBScript逐个读取值
我有一个属性文件,如下所示: FileToRead=project.xml,CheckFile.ini RunTimeFile=MyRuntime.xml使用VBScript逐个读取值,vbscript,properties,Vbscript,Properties,我有一个属性文件,如下所示: FileToRead=project.xml,CheckFile.ini RunTimeFile=MyRuntime.xml 如果在VBS中使用块,是否有可能在中使用或条件 Set fso = CreateObject("Scripting.FileSystemObject") 'Dictionary to store all the lines in form of key value pair Set dict = CreateObject("Scriptin
如果在VBS中使用块,是否有可能在中使用或条件
Set fso = CreateObject("Scripting.FileSystemObject")
'Dictionary to store all the lines in form of key value pair
Set dict = CreateObject("Scripting.Dictionary")
Set file = fso.OpenTextFile ("<InputFilePath>", 1)
'Reading the file and storing properties in the dictionary
Do Until file.AtEndOfStream
line = file.Readline
splittedLine = Split(line,"=")
if UBound(splittedLine)=1 then
dict.Add splittedLine(0),splittedLine(1)
end if
Loop
file.Close
'Now get the value from dictionary using key name FileToRead
valFileToRead = dict.item("FileToRead")
arrFiles=Split(valFileToRead,",")
for i=0 to UBound(arrFiles)
'Do anything with the values
msgBox(arrFiles(i))
next
如果是文件,脚本只读取第一行,这是故意的吗?我想从属性文件中读取两个参数,而不仅仅是第一行。如果我们指定键并读取值就可以了。您需要做的事情比您的代码现在要多得多。首先,如果以后要在换行符处拆分文件内容,应该使用
ReadAll
而不是ReadLine
。然后需要在=
处拆分每一行,以便将值与键分开。然后拆分,
处的值,并对每个循环进行第二次处理。请继续阅读。是否可以使用属性名称“FileToRead”检索属性“FileToRead”的值?(就像我们在ANT中使用${FileToRead})使用Split,我能够分离属性名和值,但是如果能够使用属性名获取值,那就太好了。
Set fso = CreateObject("Scripting.FileSystemObject")
'Dictionary to store all the lines in form of key value pair
Set dict = CreateObject("Scripting.Dictionary")
Set file = fso.OpenTextFile ("<InputFilePath>", 1)
'Reading the file and storing properties in the dictionary
Do Until file.AtEndOfStream
line = file.Readline
splittedLine = Split(line,"=")
if UBound(splittedLine)=1 then
dict.Add splittedLine(0),splittedLine(1)
end if
Loop
file.Close
'Now get the value from dictionary using key name FileToRead
valFileToRead = dict.item("FileToRead")
arrFiles=Split(valFileToRead,",")
for i=0 to UBound(arrFiles)
'Do anything with the values
msgBox(arrFiles(i))
next
if Condition1 OR Condition 2 then
'Code
end if