#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