本帖最后由 Five66 于 2023-11-28 06:34 编辑
来个偷懒的,保存为ansi编码的bat
仅处理当前路径中文件夹里的文本文件
要求文本文件编码为gbk,文件名不要有英文百分号或936代码页无法显示的字符,还有文本中如果包含^可能会被吞
改了下,已最大程度支持特殊字符(大概)- @echo off&chcp 936 >nul
-
- for /d %%a in (*) do (
- for /f "delims=" %%b in ('dir /b /s /a-d "%%a\*.txt"') do (
- setlocal
- for /f "delims=" %%c in ('findstr /n .* "%%b"') do (
- set "line=%%c"
- setlocal enabledelayedexpansion
- if "!line:*:=!" == "" (endlocal&echo,) else (
- set "line=!line:*:=!"
- for /f "delims=" %%i in ("$!line:#=^#!") do endlocal&set "line=%%i"
- set o=
- call :aaa
- )
- )
- endlocal
- )>"%%~dpb_new_%%~nxb"
- )
- pause&exit/b
-
- :aaa
- setlocal enabledelayedexpansion
- set "line=!line:~1!"
- for /f "tokens=1* delims=^" %%x in ("$!line!") do (
- endlocal&set line=&set "tk1=%%x"&set "tk2=%%y"
- )
- setlocal enabledelayedexpansion
- set "tk1=!tk1:~1!"
- if "!tk1:~0,1!" == "#" (
- if "!tk2:~0,1!" == "#" (set "line=!tk2:~1!") else set "o=!o!!tk1!"&set "line=!tk2!"
- ) else (
- set "o=!o!!tk1!"
- set "line=!tk2!"
- )
- if defined line (
- for /f "delims=" %%i in ("$!line!") do (
- for /f "delims=" %%j in (""!o!"") do endlocal&set "line=%%i"&set "o=%%~j"
- )
- goto :aaa
- ) else echo,!o!&endlocal
- goto :eof
复制代码
|