黑松山资源网 Design By www.paidiu.com
目前我找到的文件夹的搜索工具,最多可以完成把搜索到的单行的内容,进行输出出来,或者进行一些简单的处理,但是不够灵活。
因此就用lua自己写了个,可以完成自己定义搜索处理函数,进行一些数据的处理,省去了将搜索结果放到excel中再处理的过程。
-- search_log.lua tbResult = {}; tbCmdResult = {}; local szTmpFolderPath = os.getenv("temp"); if not szTmpFolderPath then os.execute("md c:\\temp") szTmpFolderPath = "c:\\temp"; end local tbSpecialWorld = { ["("] = "%(", [")"] = "%)", ["."] = "%.", ["%"] = "%%", ["+"] = "%+", ["-"] = "%-", ["*"] = "%*", [""] = "%", ["["] = "%[", ["]"] = "%]", ["^"] = "%^", ["$"] = "%$", }; function FormatCmd(szCmd) return string.gsub(szCmd, ".", function(s) return tbSpecialWorld[s] or s; end) end function FormatPath(szPath) string.gsub(szPath, "[\\/]$", ""); return string.gsub(szPath, "/", "\\"); end function CheckFile(szFilePath) local file = io.open(szFilePath, "rb"); if not file then return; end file:close(); return true; end function OpenFile(szFilePath) if not CheckFile(szFilePath) then return; end local tbFile = {}; for line in io.lines(szFilePath) do table.insert(tbFile, line); end return tbFile; end function SearchFile(szFilePath, szCmd, fnCmd2Line, fnFileName) local tbFile = OpenFile(szFilePath); if not tbFile then return; end tbResult[szFilePath] = tbResult[szFilePath] or {}; local szCmdResult = ""; for nLine, szLine in ipairs(tbFile) do if string.match(szLine, szCmd) then szCmdResult = fnCmd2Line(szLine); if szCmdResult and szCmdResult ~= "" then table.insert(tbCmdResult, szCmdResult); end table.insert(tbResult[szFilePath], nLine .. ":" .. szLine); end end return 1; end function Cmd2Line(szLine) return; end function CheckName(szFileName) return true; end function SearchDir(szFolderPath, szCmd, fnCmd2Line, fnCheckName, nIdx) if not szCmd or szCmd == "" then return; end local fnCmd2Line = fnCmd2Line or Cmd2Line; local fnCheckName = fnCheckName or CheckName; local nIdx = nIdx or 0; local szTmpFileName = szTmpFolderPath .. "\\SearchDirTemp" .. nIdx .. ".tmp"; os.execute("dir /b ".. szFolderPath .." >" .. szTmpFileName); local tbFile = OpenFile(szTmpFileName); if not tbFile or #tbFile == 0 then return; end local szPath = ""; for _, szFileName in ipairs(tbFile) do szPath = szFolderPath .. "\\" .. szFileName; if not CheckFile(szPath) then SearchDir(szPath, szCmd, fnCmd2Line, nIdx + 1); else if CheckName(szFileName) then SearchFile(szPath, szCmd, fnCmd2Line); end end end end function Write2File(szInfo, szFilePath) local file = io.open(szFilePath, "w"); if not file then print(szInfo); print("Write2File ERR " .. szFilePath); return; end file:write(szInfo); file:close(); end function DoSearchDir(szFolderPath, szCmd, tbParam) if not szFolderPath or szFolderPath == "" or not szCmd or szCmd == "" then return; end tbParam = tbParam or {}; szFolderPath = FormatPath(szFolderPath); if tbParam.bIsMatch then szCmd = FormatCmd(szCmd); end local nTime = os.time(); SearchDir(szFolderPath, szCmd, tbParam.fnCmd2Line or Cmd2Line, tbParam.fnCheckName or CheckName, 0); nTime = os.time() - nTime; print("搜索用时:" .. nTime); local szResultPath = tbParam.szResultPath or (szTmpFolderPath .. "\\result.tab.tmp"); local szResult = ""; for szFilePath, tbInfo in pairs(tbResult) do szResult = szResult .. szFilePath .. "\n"; for _, szLine in pairs(tbInfo) do szResult = szResult .. szLine .. "\n"; end end Write2File(szResult, szResultPath); local szCmdResult = ""; for _, szLine in pairs(tbCmdResult) do szCmdResult = szCmdResult .. szLine .. "\n"; end Write2File(szCmdResult, tbParam.szCmdResultPath or (szTmpFolderPath .. "\\cmd_result.tab.tmp")); end --tbParam = --{ -- bIsMatch = false; -- 是否使用正则方式搜索 -- fnCmd2Line = function () end; -- 自定义搜索行内容处理函数 -- fnCheckName = function () end; -- 文件名限定函数 -- szResultPath = "e:\\result.tab"; -- 文件搜索内容输出路径 -- szCmdResultPath = "e:\\cmd_result.tab"; -- 自定义处理函数返回内容储存路径 --}
使用代码可以如下(貌似支持网络路径的):
dofile("e:\\search_log.lua"); tbTmpInfo = {}; function CheckInfo(szLine) local szPlayerName, nPlayerId, nCount = string.match(szLine, "^.*szType = final\t[^\t]+\t%d+\t([^\t]+)\t(%d+)\t(%d+).*$"); nPlayerId = tonumber(nPlayerId); nCount = tonumber(nCount); if nCount > tbTmpInfo[nPlayerId] then tbTmpInfo[nPlayerId] = nCount; return "" .. nPlayerId .. "\t" .. nCount; end return; end tbParam = { bIsMatch = false; fnCmd2Line = CheckInfo; fnCheckName = function () return true; end; szResultPath = "e:\\result.tab"; szCmdResultPath = "e:\\cmd_result.tab"; } DoSearchDir("d:\\logs", "szType = final", tbParam); for _, szInfo in pairs(tbTmpInfo) do print(szInfo); end
唯一不满意的地方貌似是搜索速度有点慢,以后有空再调整吧,现在这个暂时够用了,至少比原来方便多了~~
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年10月10日
2024年10月10日
- 刘德华.1989-永远...记得你(2012金碟复刻版)【EMI百代】【WAV+CUE】
- 《维纳斯璀璨假期死或生Xtreme》游戏特色玩法
- 《完蛋我被美女包围了前传》角色介绍
- 2024年免费游戏加速器推荐,稳定才是王道!
- 《蛋仔派对》小海鹦兰兰皮肤图鉴
- 《蛋仔派对》憨憨小六皮肤图鉴
- 《蛋仔派对》打工小电视皮肤图鉴
- 叶启田2006-人生[台湾首版][WAV+CUE]
- [雨果唱片]陈百强2012《同名专辑LPCD45》[WAV+CUE]
- 安七炫2005-面具(中文版)[SM娱乐][WAV+CUE]
- 曝AMD曾有机会为Switch2提供芯片 却因能耗错失机会
- 《塞尔达传说:智慧的再现》新作上市宣传片公开 M站86分
- 宫本茂谈AI技术应用:任天堂更愿意走不同的路
- 《蔡琴 不了情 经典歌曲香港演唱会2CD》[ISO][6.6GB]
- 《萧煌奇 说故事的歌 2022》[FLAC/分轨][380MB]