#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3>
$Form1 = GUICreate("Extract_Line", 400, 200, 192, 114)
$Combo1 = GUICtrlCreateCombo("", 72, 20, 177, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Button1 = GUICtrlCreateButton("浏览...", 280, 10, 65, 33)
$label0=GUICtrlCreateLabel("请点击浏览选择LOG文件存放目录",72,60,220,100)
$Line = GUICtrlCreateInput("", 72, 90, 100, 20)
$Button_1= GUICtrlCreateButton ("Go", 300, 150,50, 40)
$label1=GUICtrlCreateLabel("请输入要处理的行数",72,120,220,100)
$label2=GUICtrlCreateLabel(" 2 正数第二行",72,140,220,100)
$label3=GUICtrlCreateLabel("-2 倒数第二行",72,160,220,100)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit (255)
Case $msg = $Button1
$userpath = FileSelectFolder("选择一个位置", "")
If $userpath <> "" Then
GUICtrlSetData($Combo1, "")
GUICtrlSetData($Combo1, $userpath, $userpath)
EndIf
GUICtrlSetState($Line, $GUI_FOCUS)
Case $msg = $Button_1
Go()
EndSelect
WEnd
Func GO()
$LogFile = GUICtrlRead ($Combo1)
$LogLine = GUICtrlRead ($Line)
If 0 == FileExists($LogFile & "\*.log") And 0 == FileExists($LogFile & "\*.txt") Then
MsgBox(16, "错误", $LogFile & " 没有发现 LOG 或 TXT 文件,请重新选择")
ElseIf $LogLine == "" Or $LogLine == "0" Then
MsgBox(16, "错误", "行数为空,请重新输入要处理的行数")
GUICtrlSetState($Line, $GUI_FOCUS)
Else
Extract_Line($LogFile,$LogLine)
EndIf
EndFunc
Func Extract_Line($LogFile,$LogLine)
If FileExists (@ScriptDir & "" & "out.log") Then FileDelete (@ScriptDir & "" & "out.log")
$search = FileFindFirstFile($LogFile & "\*.*")
If $search = -1 Then
MsgBox(0, "错误", "没有文件/目录 匹配搜索")
Exit
EndIf
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$CountLines = _FileCountLines($LogFile & "" & $file)
If $LogLine < 0 Then
$Data = FileReadLine($LogFile & "" & $file, $CountLines + $LogLine + 1)
EndIf
If $LogLine > 0 Then
$Data = FileReadLine($LogFile & "" & $file, $LogLine)
EndIf
$outlog = FileOpen("out.log", 9)
FileWrite($outlog, $Data & @CRLF)
FileClose($outlog)
WEnd
FileClose($search)
MsgBox(64, "", "所有数据已导入到 " & @CRLF _
& @ScriptDir & "" & "OUT.LOG")
ShellExecute("out.log")
EndFunc