2010-10-01 94 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