[已解决]如何讀取每一個資料夾裡面的Run-Prime95.log檔案內容
本帖最后由 ipmitool 于 2017-7-17 10:30 编辑如何按照順序讀取每一個資料夾裡面的Run-Prime95.log檔案內容最後一行 顯示在表格裡面 有人能幫幫忙嗎, 拜託...#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
Global $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $aHit, $hImage, $iDateCalc
Global $iColor, $iColorBk, $fChildGui = False
Local $path, $aFileList, $aNewList
$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;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 & "</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 & "</p> </th>" & @LF
Next
$sHTML = $sHTML & "</tr>" & @LF
Next
$sHTMl = $sHTMl & "</table>"
Return $sHTML
EndFunc
首先。#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.
回复 3# yamakawa
小弟還是弄不出來。。。嗚。。。 #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
Global $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $aHit, $hImage, $iDateCalc
Global $iColor, $iColorBk, $fChildGui = False
Local $path, $aFileList, $aNewList
$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)
IfIsArray($aFile)Then
For$i=1To$aFile Step1
$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 & "</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 & "</p> </th>" & @LF
Next
$sHTML = $sHTML & "</tr>" & @LF
Next
$sHTMl = $sHTMl & "</table>"
Return $sHTML
EndFunc
FuncmyFileListToArray($sPath,$rPath=0,$iFlag=0,$sPathExclude=0)
Local$asFileList ;yidabu.com提示:因为要用递归调用,$asFileList参数要单独出来
$asFileList=myFileListToArrayTemp($asFileList,$sPath,$rPath,$iFlag,$sPathExclude)
Return$asFileList
EndFunc ;==>myFileListToArray
FuncmyFileListToArrayTemp(ByRef$asFileList,$sPath,$rPath=0,$iFlag=0,$sPathExclude=0)
Local$hSearch,$sFile
IfNotFileExists($sPath)ThenReturnSetError(1,1,"")
IfNot($iFlag=0Or$iFlag=1Or$iFlag=2)ThenReturnSetError(3,3,"")
$hSearch=FileFindFirstFile($sPath&"\*")
If$hSearch=-1ThenReturnSetError(4,4,"")
While1
$sFile=FileFindNextFile($hSearch)
If@errorThen
SetError(0)
ExitLoop
EndIf
;yidabu.com提示:已经被排除的路径,就不要搜索子目录了
If$sPathExcludeAndStringLen($sPathExclude)>0Then$sPathExclude=StringSplit($sPathExclude,",")
$bExclude=False
IfIsArray($sPathExclude)Then
For$ii=1To$sPathExcludeStep1
IfStringInStr($sPath&"\"&$sFile,$sPathExclude[$ii])Then
$bExclude=True
ExitLoop
EndIf
Next
EndIf
If$bExcludeThenContinueLoop
Select
CaseStringInStr(FileGetAttrib($sPath&"\"&$sFile),"D") ;如果遇到目录
Select
Case$iFlag=1 ;求文件时就递归
myFileListToArrayTemp($asFileList,$sPath&"\"&$sFile,$rPath,$iFlag,$sPathExclude)
ContinueLoop ;求文件时跳过目录
Case$iFlag=2Or$iFlag=0 ;求目录时分两种情况
If$rPathThen ;1如果要求对路径进行正则匹配
IfNotStringRegExp($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
CaseNotStringInStr(FileGetAttrib($sPath&"\"&$sFile),"D") ;如果遇到文件
If$iFlag=2ThenContinueLoop ;求目录时就跳过
;yidabu.com提示:要求正则匹配路径,且匹配失败时就跳过。遇文件就不要递归调用了。
If$rPathAndNotStringRegExp($sPath&"\"&$sFile,$rPath,0)ThenContinueLoop
EndSelect
ReDim$asFileList
$asFileList=$asFileList+1
$asFileList=$sPath&"\"&$sFile
;$asFileList=$asFileList+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
#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];建立二维数组,第一列保存文件名,第二列保存文件最后一列文字
For $i = 1 To $aArray
$out_array[$i - 1] = $aArray[$i]
$out_array[$i] = FileReadLine($aArray[$i],-1)
Next
_ArrayDisplay($out_array)试试这个 回复 5# dtooboss
執行時Func _getdir($spath) 的$sdir = StringRegExpReplace($spath, '\\[^\\]*, '') 有問題耶, 這是因為\\[^\\]* 的關係嗎? 本帖最后由 dtooboss 于 2017-7-17 10:01 编辑
回复 7# ipmitool
$sdir = StringRegExpReplace($spath, '\\[^\\]*$', '')
不知为何论坛代码竟然过滤掉了*$ 本帖最后由 ipmitool 于 2017-7-17 10:28 编辑
回复 8# dtooboss
原來如此啊, 厲害! 那要怎樣顯示在 $idListview 上面?
這樣嗎? GUICtrlCreateListViewItem(_getdir($aFile[$i])&"|"&$str, $idListview) 回复 9# ipmitool
没错
删掉 _GUICtrlListView_AddColumn($idListview, "Tester", 0) 回复 10# dtooboss
感謝哥!
页:
[1]