下面是我托我们qq群好友 昏睡墨鱼(8876570)
搞的ahk版本:
贴出来 大家学习下- #NoEnv
- #SingleInstance force
- #Persistent
-
- FileEncoding , UTF-8
- INIFile := A_ScriptDir "\littleT.ini"
- SetWorkingDir, %A_ScriptDir%
-
- Hotkey, IfWinActive, ahk_exe explorer.exe
- ;~ 在资源管理器当前目录下生成随机 T_xxxx.txt文件,xx范围0-65535
- Hotkey, ^F3, RandomTxt
- ;~ 使用一个文件中的关键词列表(单列)批量逐行过滤文本文件,删除含关键词的行,并保存到后缀为_filted的文件中
- Hotkey, ^F4, FilterTxt
- Hotkey, IfWinActive
-
- return
-
- FilterTxt:
- tarPath := getExplorerPath()
- SetWorkingDir, %thePath%
- IniRead, ffile, %INIFile%, Save, FilterFile, %A_Space%
- ffile = %ffile%
- if (!ffile || !FileExist(ffile))
- ffile =
- SplitPath, ffile, , srcPath
- loop ; 选择过滤文件
- {
- while (!ffile)
- {
- MsgBox, 52, 选择过滤文件, 选择用于过滤的文件
- IfMsgBox, No
- goto, break_FilterTxt
- FileSelectFile, ffile, 1, %srcPath%, 请选择用于过滤的文件, 文本文件 (*.txt)
- }
-
- MsgBox, 582, 确认过滤文件, 用于过滤的文件为`n`n%ffile%`n`n请确认
- IfMsgBox, Cancel
- goto break_FilterTxt
- IfMsgBox, TryAgain
- ffile =
- } until ffile
- IniWrite, %ffile%, %INIFile%, Save, FilterFile
- loop ; 选择被过滤文件
- {
- loop
- {
- FileSelectFile, Filelist, M1, %tarPath%, 请选择要被过滤的文件, 文本文件 (*.txt)
- if (!Filelist)
- MsgBox, 52, 退出, 未要被过滤的文件`n是否退出
- IfMsgBox, Yes
- goto break_FilterTxt
- } until Filelist
- FilesbeFilte := {}
- files_ =
- loop, Parse, Filelist, `n, `r
- {
- if (A_Index=1)
- {
- FPath := A_LoopField
- files_ := FPath "`n下的"
- } else {
- nowFile := FPath "\" A_LoopField
- if (nowFile = ffile)
- {
- MsgBox, 48, 跳过文件, 文件`n`n%nowFile%`n`n是用于过滤的文件`n已跳过
- } else {
- if (RegExMatch(nowFile, "_filted"))
- continue
- FilesbeFilte.Push(nowFile)
- files_ := files_ "`n" A_LoopField
- }
- }
- }
- MsgBox, 582, 确认被过滤文件, 被过滤的文件为`n路径`n`n%files_%`n`n请确认
- ;~ sbox(ffile, FilesbeFilte)
- IfMsgBox, Cancel
- goto break_FilterTxt
- IfMsgBox, TryAgain
- files_ =
- } until files_
- SetWorkingDir, %FPath%
- for k, srcFile in FilesbeFilte
- {
- SplitPath, srcFile, , OutDir, OutExtension, OutNameNoExt
- tarFile := OutDir "\" OutNameNoExt "_filted." OutExtension
- FileDelete %tarFile%
- repLine := {}
- loop, Read, %srcFile% , %tarFile%
- {
- ;~ sbox(A_LoopReadLine, ffile)
- nLine := filterLine(A_LoopReadLine, ffile)
- ;~ 添加有内容并还未存在的行
- if (nLine && !repLine[nLine])
- FileAppend, % nLine "`n"
- repLine[nLine] := true
- }
- }
- break_FilterTxt:
- ffile=
- Filelist=
- FilesbeFilte=
- files_=
- FPath=
- nowFile=
- return
-
- filterLine(line="", file="")
- {
- if (!line || !file)
- return
- loop, Read, %file%
- {
- if !A_LoopReadLine
- return
- if RegExMatch(line, A_LoopReadLine)
- return
- }
- return, line
- }
-
- RandomTxt:
- thePath := getExplorerPath()
- Random, nfeed, 0, 65535
- FileAppend, , %thePath%\T_%nfeed%.txt
- return
-
- getExplorerPath(num=1)
- {
- WinGet, ActiveControlList, ControlList, A
- CList := "ComboBoxEx321|Edit1|ToolbarWindow323"
- loop, Parse, CList, `|
- {
- ControlGetText, OutputVar , %A_LoopField%, A
- if RegExMatch(OutputVar, "\b([A-Z]:\\.*)", Var)
- break
- }
- return Var1
- }
复制代码
|