本帖最后由 77七 于 2024-3-14 17:41 编辑
- @echo off
- cd /d "%~dp0"
- set /a b=-2,d=-2
- for %%i in (*.txt) do (
- setlocal
- call :1 "%%i"
- endlocal
- )
- pause & exit
-
- :1
- for /f "delims=" %%a in ('find /c /v "" ^<"%~1"') do (
- echo %%a
- set n=%%a
- )
- if %b% gtr 0 (
- if %d% gtr 0 (
- set /a s=b,e=b+d-1
- ) else (
- set /a s=b+d+1,e=b
- )
- ) else (
- if %d% gtr 0 (
- set /a s=n+b+1,e=s+d-1
- ) else (
- set /a s=n+b+d+2,e=n+b+1
- )
- )
- echo 删除第 %s% - %e% 行
- (for /f "tokens=1* delims=[]" %%a in ('find /n /v "" ^<"%~1"') do (
- if %%a lss %s% (
- echo=%%b
- ) else if %%a gtr %e% (
- echo=%%b
- )
- ))>$
- move $ "%~1"
- exit /b
复制代码 b 为开始行,d 为删除行数,都可以为正、负数 |