找回密码
 加入
搜索
查看: 1963|回复: 10

[AU3基础] [已解决]如何讀取每一個資料夾裡面的Run-Prime95.log檔案內容

  [复制链接]
发表于 2017-7-15 19:37:08 | 显示全部楼层 |阅读模式
本帖最后由 ipmitool 于 2017-7-17 10:30 编辑







如何按照順序讀取每一個資料夾裡面的Run-Prime95.log檔案內容最後一行 顯示在表格裡面

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2017-7-15 23:34:02 | 显示全部楼层
有人能幫幫忙嗎, 拜託...
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GuiButton.au3>


Global $hListItem[2]
Global $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $aHit, $hImage, $iDateCalc
Global $iColor, $iColorBk, $fChildGui = False

Local $path, $aFileList, $aNewList[1][2]

$path = @ScriptDir
$aFileList = _FileListToArray($path, "*.txt")

Local $iI, $iTimer, $idListview
$Main_GUI = GUICreate("Log Management v1.0", 1220, 700)
$idListview = GUICtrlCreateListView("", 15, 70, 1185, 610)
$hListView = GUICtrlGetHandle($idListview)
GUICtrlSetBkColor(-1, 0xFFFFDD);0x0000FF);


_GUICtrlListView_SetBkColor($idListview, 14675183);$CLR_MONEYGREEN);
$hImage = _GUIImageList_Create(1, 18);30为每行的间距(即网格高度)
_GUICtrlListView_SetImageList($idListview, $hImage, 1)
_GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))
_GUICtrlListView_AddColumn($idListview, "Tester", 0)
_GUICtrlListView_AddColumn($idListview, "Folder", 60)
_GUICtrlListView_AddColumn($idListview, "Description1", 500)
_GUICtrlListView_AddColumn($idListview, "Description2", 500)
_GUICtrlListView_AddColumn($idListview, "Description3", 100)
_GUICtrlListView_AddColumn($idListview, "Description4", 100)
_GUICtrlListView_AddColumn($idListview, "Description5", 100)


$input1 = GUICtrlCreateInput("48", 2140, 20, 90, 20, $ES_CENTER, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 12, 400, 0, 'Verdana')
GUICtrlSetLimit(-1, 9);控制字符长度
$ad = @ScriptDir & "\1.bmp"


$buttonPrime95 = GUICtrlCreateButton("Prime95", 115, 16, 88, 30, $BS_BITMAP, $WS_EX_DLGMODALFRAME)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
;_GUICtrlButton_SetImage($buttonPOST, $ad)

$button2 = GUICtrlCreateButton("Dump HTML", 415, 16, 88, 30, $BS_BITMAP, $WS_EX_DLGMODALFRAME)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
_GUICtrlButton_SetImage($button2, $ad)

$button3 = GUICtrlCreateButton("Exit", 515, 16, 88, 30, $BS_BITMAP, $WS_EX_DLGMODALFRAME)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
_GUICtrlButton_SetImage($button3, $ad)


GUISetState(@SW_SHOW)


_Txt2()







While 1
        $Msg = GUIGetMsg()
        Switch $Msg
                Case $GUI_EVENT_CLOSE
                        Exit


                           Case $buttonPrime95
                                                _Txt2()

                 Case $button2
                                                FileChangeDir(@ScriptDir)
                                                FileWrite ("TestStatus_Export_"&@YEAR&@MON&@MDAY&@HOUR&@min&@sec&".html", _ListViewToHTMLTable($idListview))
                                                MsgBox(0,"","Dump html file to: " & @ScriptDir & ""&"table"&@YEAR&@MON&@MDAY&@HOUR&@min&".html")
                Case $button3
                        Exit



        EndSwitch
WEnd










Func _Txt2()
        GUICtrlSendMsg($idListview, $LVM_DELETEALLITEMS, 0, 0)

        Local $sComboTxt = "All"



        Local $FileLista = _FileListToArray(@ScriptDir&"\Run-Prime95", "*", Default, True)
        For $i = 1 To $FileLista[0];10

                $FileList = _FileListToArray(@ScriptDir&"\Run-Prime95", "*", 2)

                $fFolder = _ArrayToString($FileLista)



                $fFolder = StringTrimLeft($fFolder, 2)
MsgBox(0,"1",$fFolder)

                $Openlog = FileOpen(@ScriptDir&"\Run-Prime95" & $fFolder & "\Run-Prime95.log")



                $filelog = @ScriptDir&"\Run-Prime95" & $fFolder & "\Run-Prime95.log"



                $OpenlogReadLine6 = FileReadLine($Openlog, 10)
                                $OpenlogReadLine7 = FileReadLine($Openlog, 11)
                                $OpenlogReadLine8 = FileReadLine($Openlog, 12)
                                $OpenlogReadLine9 = FileReadLine($Openlog, 13)
                                $OpenlogReadLine10 = FileReadLine($Openlog, 14)

                                Local $arr1 = "|" & $i

                Local $arr6 = "|" & $OpenlogReadLine6
                                Local $arr7 = "|" & $OpenlogReadLine7
                                Local $arr8 = "|" & $OpenlogReadLine8
                                Local $arr9 = "|" & $OpenlogReadLine9
                                Local $arr10 = "|" & $OpenlogReadLine10



                If Not StringInStr($sComboTxt, $arr6) Then $sComboTxt &= $arr6
                GUICtrlCreateListViewItem($arr1 & $arr6 & $arr7& $arr8& $arr9& $arr10, $idListview)

        Next

EndFunc   ;==>_Txt



;-----------------------------------------------------------------------------------------------------------






Func _ListViewToHTMLTable($hList)
        Local $sHTML,$iColCount,$iRowCount
        $iColCount = _GUICtrlListView_GetColumnCount($hList)

        $sHTML = "<P></P><B>Test Management Tool Report @DateTime: "&@YEAR&"/"&@MON&"/"&@MDAY&" "&@HOUR&":"&@min&":"&@SEC&"</B>"&"<P></P>"&"<table width='1500' border='2' BGColor='#c4d6f6'>" & @LF & "<tr>" & @LF
        ;创建表头
        For $i = 1 To $iColCount-1
                $aInfo = _GUICtrlListView_GetColumn($hList, $i)
                $sHTML = $sHTML & "<th scope='col' BGColor='#FFFFFF'>" & $aInfo[5] & "</th>" & @LF
        Next
        ;添加数据
        $iRowCount = _GUICtrlListView_GetItemCount($hList)
        For $i = 0 To $iRowCount - 1
                $sHTML = $sHTML & "<tr>" & @LF
                For $j = 1 To $iColCount-1
                        $aInfo = _GUICtrlListView_GetItem($hList, $i, $j)
                        $sHTML = $sHTML & "<th><p align=""left"">" & $aInfo[3] & "</p> </th>" & @LF
                Next
                $sHTML = $sHTML & "</tr>" & @LF
        Next

        $sHTMl = $sHTMl & "</table>"

        Return $sHTML
EndFunc
发表于 2017-7-16 10:00:01 | 显示全部楼层
首先。
#include <File.au3>
_FileListToArrayRec ( $sFilePath [, $sMask = "*" [, $iReturn = $FLTAR_FILESFOLDERS [, $iRecur = $FLTAR_NORECUR [, $iSort = $FLTAR_NOSORT [, $iReturnPath = $FLTAR_RELPATH]]]]] )
读取文件到数组,然后循环读取
FileReadLine ( "filehandle/filename" , -1)


FileReadLine
读取文本文件指定行的文本.


FileReadLine ( "filehandle/filename" [, line = 1] )


参数
filehandle/filename 由此前 FileOpen() 函数返回的文件句柄. 也可以使用文件名字符串作为参数. 
line [可选] 读取的行号. 文本文件的第一行为 1(不为 0), 最后一行为 -1. 
 楼主| 发表于 2017-7-16 21:28:18 | 显示全部楼层
回复 3# yamakawa

小弟還是弄不出來。。。嗚。。。
发表于 2017-7-16 22:41:03 | 显示全部楼层
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GuiButton.au3>


Global $hListItem[2]
Global $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $aHit, $hImage, $iDateCalc
Global $iColor, $iColorBk, $fChildGui = False

Local $path, $aFileList, $aNewList[1][2]

$path = @ScriptDir
$aFileList = _FileListToArray($path, "*.txt")

Local $iI, $iTimer, $idListview
$Main_GUI = GUICreate("Log Management v1.0", 1220, 700)
$idListview = GUICtrlCreateListView("", 15, 70, 1185, 610)
$hListView = GUICtrlGetHandle($idListview)
GUICtrlSetBkColor(-1, 0xFFFFDD);0x0000FF);


_GUICtrlListView_SetBkColor($idListview, 14675183);$CLR_MONEYGREEN);
$hImage = _GUIImageList_Create(1, 18);30为每行的间距(即网格高度)
_GUICtrlListView_SetImageList($idListview, $hImage, 1)
_GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))
_GUICtrlListView_AddColumn($idListview, "Tester", 0)
_GUICtrlListView_AddColumn($idListview, "Folder", 60)
_GUICtrlListView_AddColumn($idListview, "Description1", 500)
_GUICtrlListView_AddColumn($idListview, "Description2", 500)
_GUICtrlListView_AddColumn($idListview, "Description3", 100)
_GUICtrlListView_AddColumn($idListview, "Description4", 100)
_GUICtrlListView_AddColumn($idListview, "Description5", 100)


$input1 = GUICtrlCreateInput("48", 2140, 20, 90, 20, $ES_CENTER, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 12, 400, 0, 'Verdana')
GUICtrlSetLimit(-1, 9);控制字符长度
$ad = @ScriptDir & "\1.bmp"


$buttonPrime95 = GUICtrlCreateButton("Prime95", 115, 16, 88, 30, $BS_BITMAP, $WS_EX_DLGMODALFRAME)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
;_GUICtrlButton_SetImage($buttonPOST, $ad)

$button2 = GUICtrlCreateButton("Dump HTML", 415, 16, 88, 30, $BS_BITMAP, $WS_EX_DLGMODALFRAME)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
_GUICtrlButton_SetImage($button2, $ad)

$button3 = GUICtrlCreateButton("Exit", 515, 16, 88, 30, $BS_BITMAP, $WS_EX_DLGMODALFRAME)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
_GUICtrlButton_SetImage($button3, $ad)


GUISetState(@SW_SHOW)



 _Txt2()



While 1
        $Msg = GUIGetMsg()
        Switch $Msg
                Case $GUI_EVENT_CLOSE
                        Exit


                           Case $buttonPrime95
                         ;                       _Txt2()

                 Case $button2
                                                FileChangeDir(@ScriptDir)
                                                FileWrite ("TestStatus_Export_"&@YEAR&@MON&@MDAY&@HOUR&@min&@sec&".html", _ListViewToHTMLTable($idListview))
                                                MsgBox(0,"","Dump html file to: " & @ScriptDir & ""&"table"&@YEAR&@MON&@MDAY&@HOUR&@min&".html")
                Case $button3
                        Exit



        EndSwitch
WEnd










Func _Txt2()
$sPath = "."
$aFile  =  myFileListToArray($sPath,  "Run-Prime95.log",1)
If  IsArray($aFile)  Then  
     For  $i  =  1  To  $aFile[0]    Step  1
$lin = _FileCountLines($aFile[$i])
$str = FileReadLine($aFile[$i],$lin)
MsgBox(4096,_getdir($aFile[$i]),$str)

    Next
EndIf                 

EndFunc   ;==>_Txt



;-----------------------------------------------------------------------------------------------------------






Func _ListViewToHTMLTable($hList)
        Local $sHTML,$iColCount,$iRowCount
        $iColCount = _GUICtrlListView_GetColumnCount($hList)

        $sHTML = "<P></P><B>Test Management Tool Report @DateTime: "&@YEAR&"/"&@MON&"/"&@MDAY&" "&@HOUR&":"&@min&":"&@SEC&"</B>"&"<P></P>"&"<table width='1500' border='2' BGColor='#c4d6f6'>" & @LF & "<tr>" & @LF
        ;创建表头
        For $i = 1 To $iColCount-1
                $aInfo = _GUICtrlListView_GetColumn($hList, $i)
                $sHTML = $sHTML & "<th scope='col' BGColor='#FFFFFF'>" & $aInfo[5] & "</th>" & @LF
        Next
        ;添加数据
        $iRowCount = _GUICtrlListView_GetItemCount($hList)
        For $i = 0 To $iRowCount - 1
                $sHTML = $sHTML & "<tr>" & @LF
                For $j = 1 To $iColCount-1
                        $aInfo = _GUICtrlListView_GetItem($hList, $i, $j)
                        $sHTML = $sHTML & "<th><p align=""left"">" & $aInfo[3] & "</p> </th>" & @LF
                Next
                $sHTML = $sHTML & "</tr>" & @LF
        Next

        $sHTMl = $sHTMl & "</table>"

        Return $sHTML
        EndFunc
        
        
Func  myFileListToArray($sPath,  $rPath  =  0,  $iFlag  =  0,  $sPathExclude  =  0)
    Local  $asFileList[1][1]        ;yidabu.com提示:因为要用递归调用,$asFileList参数要单独出来
    $asFileList  =  myFileListToArrayTemp($asFileList,  $sPath,  $rPath,  $iFlag,  $sPathExclude)
    Return  $asFileList
EndFunc    ;==>myFileListToArray

Func  myFileListToArrayTemp(ByRef  $asFileList,  $sPath,  $rPath  =  0,  $iFlag  =  0,  $sPathExclude  =  0)
    Local  $hSearch,  $sFile
    If  Not  FileExists($sPath)  Then  Return  SetError(1,  1,  "")
    If  Not  ($iFlag  =  0  Or  $iFlag  =  1  Or  $iFlag  =  2)  Then  Return  SetError(3,  3,  "")
    $hSearch  =  FileFindFirstFile($sPath  &  "\*")
    If  $hSearch  =  -1  Then  Return  SetError(4,  4,  "")
    While  1
        $sFile  =  FileFindNextFile($hSearch)
        If  @error  Then
            SetError(0)
            ExitLoop
        EndIf
        
        ;yidabu.com提示:已经被排除的路径,就不要搜索子目录了
        If  $sPathExclude  And  StringLen($sPathExclude)  >  0  Then  $sPathExclude  =  StringSplit($sPathExclude,  ",")
        $bExclude  =  False
        If  IsArray($sPathExclude)  Then
            For  $ii  =  1  To  $sPathExclude[0]  Step  1
                If  StringInStr($sPath  &  ""  &  $sFile,  $sPathExclude[$ii])  Then
                    $bExclude  =  True
                    ExitLoop
                EndIf
            Next
        EndIf
        If  $bExclude  Then  ContinueLoop
        
        Select
            Case  StringInStr(FileGetAttrib($sPath  &  ""  &  $sFile),  "D")    ;如果遇到目录
                Select
                    Case  $iFlag  =  1    ;求文件时就递归
                        myFileListToArrayTemp($asFileList,  $sPath  &  ""  &  $sFile,  $rPath,  $iFlag,  $sPathExclude)
                        ContinueLoop    ;求文件时跳过目录
                    Case  $iFlag  =  2  Or  $iFlag  =  0    ;求目录时分两种情况
                        If  $rPath  Then    ;1如果要求对路径进行正则匹配
                            If  Not  StringRegExp($sPath  &  ""  &  $sFile,  $rPath,  0)  Then    ;正则匹配失败就递归
                                myFileListToArrayTemp($asFileList,  $sPath  &  ""  &  $sFile,  $rPath,  $iFlag,  $sPathExclude)
                                ContinueLoop    ;正则匹配失败时跳过本目录
                            Else    ;正则匹配成功就递归,并把本目录加入匹配成功                                
                                myFileListToArrayTemp($asFileList,  $sPath  &  ""  &  $sFile,  $rPath,  $iFlag,  $sPathExclude)
                            EndIf
                        Else    ;2如果不要求对路径进行正则匹配,递归,并把本目录加入匹配成功,
                            myFileListToArrayTemp($asFileList,  $sPath  &  ""  &  $sFile,  $rPath,  $iFlag,  $sPathExclude)
                        EndIf
                EndSelect
                
            Case  Not  StringInStr(FileGetAttrib($sPath  &  ""  &  $sFile),  "D")    ;如果遇到文件
                If  $iFlag  =  2  Then  ContinueLoop    ;求目录时就跳过
                ;yidabu.com提示:要求正则匹配路径,且匹配失败时就跳过。遇文件就不要递归调用了。
                If  $rPath  And  Not  StringRegExp($sPath  &  ""  &  $sFile,  $rPath,  0)  Then  ContinueLoop
        EndSelect
        
        ReDim  $asFileList[UBound($asFileList)  +  1]
        $asFileList[0]  =  $asFileList[0]  +  1
        $asFileList[UBound($asFileList)  -  1]  =  $sPath  &  ""  &  $sFile 
                ;$asFileList[0][0]  =  $asFileList[0][0]  +  1
    WEnd
    FileClose($hSearch)
    Return  $asFileList
EndFunc    ;==>myFileListToArrayTemp


Func _getdir($spath)
        If StringRegExp($spath, '\\') Then
                $sdir = StringRegExpReplace($spath, '\\[^\\]*, '')
        Else
                $sdir = ''
        EndIf

        Return ($sdir)
EndFunc   ;==>_getdir

评分

参与人数 1金钱 +40 收起 理由
ipmitool + 40 感謝您!

查看全部评分

发表于 2017-7-16 23:15:03 | 显示全部楼层
        #include <Array.au3>
        #include <File.au3>
        Local $base_path = "d:";文件所在顶层目录
        Local $dbfile = "Run-Prime95.log"
        
        Local $aArray = _FileListToArrayRec($base_path, $dbfile, 1, 1, 1,2)
        _ArrayDisplay($aArray);输出看看,是不是所有文件都有搜到,确认没问题这句可以删除或者注销
        
        Local $out_array[$aArray[0]][2];建立二维数组,第一列保存文件名,第二列保存文件最后一列文字

        For $i = 1 To $aArray[0]
                $out_array[$i - 1][0] = $aArray[$i]
                $out_array[$i][1] = FileReadLine($aArray[$i],-1)
        Next
        
_ArrayDisplay($out_array)
试试这个

评分

参与人数 1金钱 +40 收起 理由
ipmitool + 40 謝謝您喔!

查看全部评分

 楼主| 发表于 2017-7-17 08:04:58 | 显示全部楼层
回复 5# dtooboss


    執行時Func _getdir($spath) 的  $sdir = StringRegExpReplace($spath, '\\[^\\]*, '') 有問題耶, 這是因為\\[^\\]* 的關係嗎?
发表于 2017-7-17 10:00:18 | 显示全部楼层
本帖最后由 dtooboss 于 2017-7-17 10:01 编辑

回复 7# ipmitool


                    $sdir = StringRegExpReplace($spath, '\\[^\\]*$', '')




不知为何论坛代码竟然过滤掉了*$
 楼主| 发表于 2017-7-17 10:26:44 | 显示全部楼层
本帖最后由 ipmitool 于 2017-7-17 10:28 编辑

回复 8# dtooboss


    原來如此啊, 厲害! 那要怎樣顯示在 $idListview 上面?

這樣嗎? GUICtrlCreateListViewItem(_getdir($aFile[$i])&"|"&$str, $idListview)
发表于 2017-7-17 11:06:31 | 显示全部楼层
回复 9# ipmitool


没错

删掉 _GUICtrlListView_AddColumn($idListview, "Tester", 0)
 楼主| 发表于 2017-7-17 11:51:37 | 显示全部楼层
回复 10# dtooboss


    感謝哥!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-5 20:48 , Processed in 0.085745 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表