2017-03-02 54 views
-2

我需要從多個report.html grep「狀態」,並製作一個組合的報告,這些報告保存在下面的目錄。用**突出顯示的所有目錄對於每個報告都不相同。我怎麼能做到這一點。 C:\ Program Files(x86)\ Jenkins \ jobs ** E2E_Sanity ** \ jobs ** ABC_E2E_Sanity ** \ builds ** 41 ** \ archive \ performanceTestsReports ** pcRun106821 ** \ Report循環通過多個目錄,並閱讀狀態的HTML文件

+0

有了一個for循環?你可以給你當前的實施更多的支持? – Adonis

+1

Python Java Groovy ...選擇一個 –

回答

0

例如,使用蟒蛇和glob模塊:

import glob 

files = r"C:\Program Files (x86)\Jenkins\jobs*\jobs*\builds*\archive\performanceTestsReports*\Report" 
l = glob.glob(files) 
for f in l: 
    print (f) 
0

找到一個小常規程序,可以:

  • 提取物修復行號(如果狀態是在固定的行)
  • 搜索一個字 - 狀態並提取信息息

    int lineNo = 1 
    //if the row number is fixed you can extracted by minLine and maxLine 
    int minLine = 1 
    int maxLine = 20 
    def line 
    def status 
    def statusRegex 
    
    
    def folder = new File("C:\\Users\\user\\Desktop\\ero") 
    
    folder.eachFile{it-> 
    println "File: ${it.absolutePath}" 
    
    it.withReader { reader-> 
        while ((line = reader.readLine()) != null & lineNo <= maxLine) { 
    
         if (lineNo >= minLine) { 
          //  println "${lineNo}. ${line}" //if you need specific line numbers 
         } 
         lineNo++ 
         //search for status and print the line 
         status = line.find("status") 
         //search for status by regex and extract all up to < 
         statusRegex = line.find(/(?s)status (.*?)\</) 
    
         if(status){ 
          println ' full line' + line 
         } 
         if(statusRegex){ 
          println ' by regex' + statusRegex 
         } 
        } 
    } 
    }