如何用vbs获取指定路径下的文件名并输出到文本文件?
把文本文件处理为数组,每行为一个数组元素,然后在每个元素中查找关键词,vbs可以直接使用instr函数来查找,也可以使用正则表达式查找。找到后把那个数组元素复制出来就可以了。第一种,使用instrc = split(createobject("scripting.filesystemobject").opentextfile("a.txt").readall,vbcrlf)for i = 0 to ubound(c)if instr(c(i),"nice") then msgbox c(i)next第二种,使用正则表达式c = split(createobject("scripting.filesystemobject").opentextfile("a.txt").readall,vbcrlf)for i = 0 to ubound(c)if rt("nice",c(i)) then msgbox c(i)nextFunction rt(patrn,str)set regex=new regexpregex.pattern = patrnregex.ignorecase = falsert = regex.test(str)End Function