求这个批处理写的处理工具怎么转换成Au3来写
最下面一段提取出所有包含关键字的行到一个文本中不知道怎么解决,我只能提取某一行的,set Log_Path=F:\Test_Logset Fail_Log_Path=F:\Fail_Log
if not exist %Fail_Log_Path%\nul mkdir %Fail_Log_Path%
del /s /q %Fail_Log_Path%\*.log
cd /d %Fail_Log_Path%
for /f "tokens=1* delims=" %%a in ('dir /s /b %Log_Path%\*Fail.log') do (
move /y %%a %Fail_Log_Path%
)
for /f "tokens=1,2* delims=_" %%a in ('dir /b *.log') do (
if defined #%%b (
del /f /q %%a_%%b_%%c
) else (
set #%%b=1
)
)
for /f "tokens=1* delims=." %%a in ('dir /b *.log') do (
for /f "tokens=9 delims=_" %%i in ("%%a") do (
if not exist .\%%i mkdir .\%%i
move /y %%a.%%b .\%%i
)
)
for /f %%i in ('dir /A:D /B') do (
for /f %%A in ('dir /b .\%%i\*.log') do (
for /f "skip=1 delims=`" %%a in ('findstr /i ",Fail," .\%%i\%%A') do echo %%a >> F:\%%i.txt
)
)
pause > nul这个是我写的提取其中一行的代码,呵呵 ~~#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 回复 1# jwwlchen
指处理快忘光了. 按你的意图,给了个截取关键字行的示例#include <file.au3>
#include <array.au3>
Local $text, $a, $keyword
$text = FileRead('log.txt')
$keyword = '出局'
$a = StringRegExp($text, '.*' & $keyword & '.*', 3)
If @error Then Exit MsgBox(0, $keyword, '匹配结果为空!')
_ArrayDisplay($a)
;_FileWriteFromArray('out.txt', $a) 回复 2# user3000
感谢,我试下先
页:
[1]