2010-10-01 109 views
0

在我的bat脚本中,是否可以访问txt文件并逐行读取它。我的想法是检查行是否以标识符词开始(在我的例子中是1或2星***),但要做到这一点,我需要逐行读取文件。蝙蝠按行读取文件

回答

2

您可以使用VBScript

strToFind= WScript.Arguments(0) 
strToFind = Replace(strToFind,"*","\*") 
strFileName = WScript.Arguments(1) 
Set objFS = CreateObject("Scripting.FileSystemObject") 
Set objFile = objFS.OpenTextFile(strFileName) 
Set objRE = New RegExp 
objRE.IgnoreCase = False 
objRE.Pattern = "^"&strToFind&".*" 
Do Until objFile.AtEndOfStream  
    strLine = objFile.ReadLine 
    Set Matches = objRE.Execute(strLine) 
    'WScript.Echo Matches.Count 
    For Each Match in Matches ' Iterate Matches collection.    
     WScript.Echo Match.Value   
    Next   
Loop  
objFile.Close 

用法:

C:\test>cscript //nologo myscript.vbs "**" file