bat下该如何实现查找指定文件下的字符串并替换?
发布网友
发布时间:2022-04-24 05:02
我来回答
共2个回答
热心网友
时间:2022-05-02 04:25
Dim strFile: strFile = "c:\1.txt"
Dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject")
Dim objFile: Set objFile = FSO.OpenTextFile(strFile)
Dim strContent: strContent = objFile.Readall
objFile.Close
Dim objRegEx: Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.IgnoreCase = True
objRegEx.Pattern = "bxn"
Dim objNewText: objNewText = objRegEx.Replace(strContent,"trg")
Dim objTextFile: Set objTextFile = FSO.CreateTextFile("c:\op.vbs")
objTextFile.Write objNewText
Wscript.Quit
热心网友
时间:2022-05-02 05:43
@echo off&setlocal
set f1="c:\123.txt"
set f2="c:\123.vbs"
set src=bxn
set dst=trg
(for /f "usebackq delims=" %%a in (%f1%) do (
set v=%%a
setlocal enabledelayedexpansion
set v=!v:%src%=%dst%!
echo.!v!
endlocal
))>%f2%
pause
goto :eof