提高效率的办法是将一次 dir 的输出重定向到文件,然后用 for 排除,不过要想完全模拟顶楼代码,估计效率恐怕也不怎么滴,而且代码很长,费力不讨好:- @echo off&setlocal enabledelayedexpansion
- set dircmd=C:\
- dir /s|findstr /n /v /r /c:"所列文件总数" /c:"Total Files Listed" /c:"^[ 0-9]*Dir" /c:"^[ 0-9]*个目录">tmp.txt
- for /f "delims=:" %%a in ('find /c /v ""^<tmp.txt') do set /a all=%%a-1
- (for /f "delims==" %%a in ('set') do set %%a=
- set all=%all%
- set /p a=&set /p b=)<tmp.txt
- for /f "tokens=1*" %%a in ('dir') do set end=%%b
- for /f %%a in ('copy /z %0 nul') do set hh=%%a^
-
-
- (for /f "tokens=1* skip=3 delims=:" %%a in (tmp.txt) do (
- if %%a lss %all% (
- for /f "eol=2 tokens=1,2 delims=\" %%c in ("%%b") do (
- if /i "%%c"==" C:" (
- if /i "%%c\%%d"==" C:\Windows" (
- set echo=
- ) else (
- set echo=1
- echo %a:~2%!hh!%b:~2%!hh!
- )
- ) else (
- set "str= !n!"
- set n=-2
- echo !str:~-16! %end%
- set str=
- )
- )
- if defined echo echo;%%b
- for /f "tokens=2 delims=<>" %%c in ("%%b") do (
- if /i %%c==DIR set /a n+=1
- )
- )
- ))>结果.txt
- del /f tmp.txt>nul
- pause
复制代码 为了省事,此代码不考虑文件名中的特殊字符... |