本帖最后由 skynjupt 于 2013-4-26 13:05 编辑
下面的批处理只会修改本文件夹下的TXT文本(不包括子文件下的TXT文本)- @echo off&chcp 936>nul&color 0A
-
- mkdir tempFile 2>nul
-
- for %%i in (*.txt) do (
- cd.>.\tempFile\%%~ni.temp
- call :subFun %%i
- )
-
- pushd ".\tempFile"
- ren *.temp *.txt 1>nul
- popd
-
- move /y .\tempFile\*.txt .\ 1>nul
- rd /q /s tempFile
-
- echo 处理完毕,按任意键结束...
- pause>nul&exit
-
- ::第一个参数为文件名
- :subFun
- setlocal EnableDelayedExpansion
- set "b=0"
- for /f "delims=" %%j in (%~1) do (
- if "%%j" neq "" (
- if !b! equ 0 (
- set "b=1"
- set "lines=%%j"
- set "line_1=!lines:~,20!"
- set "line_2=!lines:~19!"
- echo ^<a^>!line_1!^</a^>!line_2!>>.\tempFile\%~n1.temp
- ) else (
- echo %%j>>.\tempFile\%~n1.temp
- )
- )
- )
- endlocal
- goto :eof
复制代码
|