本帖最后由 terse 于 2023-2-19 20:14 编辑
先测试效率能否提高,其他要求再说
PS:修改了输出文件编码为UTF-8 文件名result.txt
另外 测试文件夹名为text 你自行修改代码第二行- @if(0)==(0) echo off
- set "folder=text"
- dir "%folder%\*.*" /b /a-d /s |cscript.exe //NoLogo //E:JScript "%~f0"
- pause&exit
- @end
-
- function SaveText(filename, text, charset) {
- var stream;
- stream = new ActiveXObject("ADODB.Stream");
- stream.type = 2;
- stream.charset = charset;
- stream.open();
- stream.writeText(text);
- stream.saveToFile(filename, 2);
- stream.close();
- }
-
- var fso = new ActiveXObject('Scripting.FileSystemObject'),
- re = /(Code="|Name="|Tender=")([^"]+)"/img,
- result = ''
-
- while (!WSH.StdIn.AtEndOfStream){
- var file = WSH.StdIn.ReadLine(),
- f = fso.OpenTextFile(file,1),
- content = f.ReadAll();
- f.Close();
- content.replace(re, function($a,$b,$c)
- {
- file += $c != null ? ( ' ' + $c ):'';
- })
- result += result != '' ? '\n' + file : file
-
- }
- SaveText("result.txt",result,"utf-8")
- WSH.Echo(result)
复制代码
- @echo off
- set "folder=text"
- powershell "[regex]$re = '(?smi)(?<=Name=\"^|Code=\"|Tender=\")([^^\"]*)';(dir %folder% -File -Recurse).FullName.ForEach({$_+ ' '+($re.Matches((gc $_ -Raw)).Value -join ' ')}) | Out-File result.txt -Encoding utf8 "
- pause
复制代码
|