批处理,替换(或者删除)当前文件夹中所有TXT文档中指定的字符?

2025-03-13 08:33:56
推荐回答(1个)
回答1:

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /b "*.txt"') do (
for /f "skip=2 delims=" %%a in ('find /v "%%" "%%i"') do (
set "word1=%%a"
set "word1=!word1:123=abc!"
set "word2=!word1!"
set "word2=!word2:456=xyz!"
set "word3=!word2!"
set "word3=!word2:444=!"
echo,!word3! >>"%%~ni_tmp.txt"
)
del "%%i" /f /q
ren "%%~ni_tmp.txt" "%%i"
)
pause

注:把批处理文件跟txt放在一起运行,测试前先备份好原文件

您的采纳是我们的动力和鼓励,请及时点击【采纳回答】