|
|
发表于 2025-9-14 16:44:01
|
显示全部楼层
本帖最后由 aloha20200628 于 2025-9-14 16:55 编辑
用批处分别调用 powershell, jscript, gawk 功能练了一把本题,即在当前目录(包含子目录)下获取最长路径及其长度值,实测结果是 gawk 效率最高,jscript 次之...
一。bat+powershell 版(存为 test1.bat 运行)
- @echo off &dir /b/s/ad>#.$
- powershell "$m=1;(gc '#.$')|%%{if($m -lt $_.length){$m=$_.length;$z=$_}};'最长路径及其长度:'+$z+' 》'+$m"
- del /q "#.$" &pause&exit/b
复制代码 二。bat+jscript 版(存为 test2.bat 运行)
- 2>1/* ::
- @echo off &dir /b/s/ad|cscript /nologo /e:jscript "%~f0"
- pause&exit/b */
- ws=WSH.stdin,nmax=1;
- while (!ws.atendofstream) {
- s=ws.readline(), n=s.length;
- if (n>nmax) nmax=n, smax=s; }
- WSH.echo('最长路径及其长度:'+smax+' 》'+nmax), WSH.quit();
复制代码 三。bat+gawk 版(存为 test3.bat 运行)本坛第三方下载 http://bcn.bathome.net/s/tool/index.html?key=gawk 落地即用,与批处脚本同目录
- @echo off &dir /b/s/ad>#.$
- gawk "{if(length(max)<length())max=$0}END{printf "最长路径及其长度:%%s 》%%d\n",max,length(max)}" "#.$">con
- del /q "#.$" &pause&exit/b
复制代码 |
|