bat批处理的代码如下 @echo off setlocal enabledelayedexpansion :: 设置文件夹路径 set "folderPath=D:\txt\" :: 遍历文件夹里的所有 txt 文件 for %%F in (%folderPath%\*.txt) do ( set "inputFile=%%F" set "outputFile=%%F_temp.txt" :: 第一步:替换特定字符为空 powershell -Command "(Get-Content '!inputFile!') -replace '[「」【】]', '' | Set-Content '!outputFile!'" :: 第二步:用正则表达式限制每行的字符数并添加新行 powershell -Command "(Get-Content '!outputFile!') -replace '(.{6,18}[,。:!?]|.{16})', '$1`n' | Set-Content '!outputFile!'" :: 第三步:替换特定字符为空 powershell -Command "(Get-Content '!outputFile!') -replace '[,。!]', '' | Set-Content '!outputFile!'" :: 第四步:移除空行 powershell -Command "(Get-Content '!outputFile!') | ? {$_ -ne ''} | Set-Content '!outputFile!'" :: 替换原文件 move /Y "!outputFile!" "!inputFile!" echo 文件 %%F 处理完成! ) echo 所有文件处理完成! pause 其中第二步中的用正则表达式限制每行的字符数并添加新行 powershell -Command "(Get-Content '!outputFile!') -replace '(.{6,18}[,。:!?]|.{16})', '$1`n' | Set-Content '!outputFile!'" 可以实现正则定位,但是无法实现换行,要如何修改,\n \r 设置了无效? $1 部分正常识别,但是一到换行就直接输出 n 并不能换行