作者:dbyoung
在网上找了很久,想用 CMD/BAT 批处理的方式,来进行文件的字符串搜索替换工作。
看了,试了,一大堆。
不是有问题,就是有瑕疵。不能完美解决问题。
只好自己想,自己做了。
我给出的方案,完美解决问题。
而且简单。简单得不能再简单了。
cmd/bat 示例文本:
@echo off
setlocal EnableDelayedExpansion
set "CurrCD=%~dp0"
set "strOld=aaaaa"
set "strNew=zzzzz"
:: 将当前目录(包括子目录)下的所有 TXT 文本中的 aaaaa 替换为 zzzzz
for /f %%i in ('dir /b /s /a:-d *.txt') do (
powershell -Command "(gc %%i) -replace '%strOld%', '%strNew%' | Out-File %%i"
powershell ...... 这句话后面还可以跟字符编码格式幺。
特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.