文件字符串替换

文件字符串替换

@echo off

echo ***** Replace "abcd" as "ABCD" *****
set strFilePath=C:\Users\Leez\Desktop\TestBat\TestSource.txt
set strOld=abcd
set strNew=ABCD

setlocal enabledelayedexpansion
for /f "tokens=*" %%i in (%strFilePath%) do (
    set "var=%%i"
    if not !var!.==. (
        set "var=!var:%strOld%=%strNew%!"
        echo !var!!>>%strFilePath%.bk
    )
)

move /y %strFilePath%.bk %strFilePath%

pause

 

posted @ 2016-05-10 11:21  sz_leez  阅读(714)  评论(0编辑  收藏  举报