本帖最后由 yhcfsr 于 2018-3-27 16:05 编辑
【修正】优化上面的代码,效率比上面那个快10倍不止- @echo off
- rem 源目录
- set "SrcDir=D:\test"
-
- for /f "delims=" %%a in ('dir /a-d/s/b "%SrcDir%\*.txt"') do (
- set line=&set n=
- for /f "delims=[]" %%b in ('find /n "#" ^<"%%a"') do if not defined line set/a line=%%b
- if defined line (
- (for /f "delims=" %%b in ('findstr /n ".*" "%%a"') do (
- set/a n+=1&set "var=%%b"
- setlocal enabledelayedexpansion
- if !n! lss !line! set "var=!var:*:=!"&&echo;!var!
- endlocal
- ))>"%%a.log"
- if exist "%%a.log" move /y "%%a.log" "%%a"
- )
- )
复制代码
|