@echo off
::把需要搜索的路径赋值给变量sp,这里举例是c:\tmp
set sp=d:\tmp
::把需要查找的文件名赋值给变量cf,这里举例是root.txt
set cf=root.txt
::把将被替换的字符串赋值给st,这里举例是apple
set st=111111
::把替换字符串赋值给dt,这里举例是lemon
set dt=PWD
BatchFile code
@echo off
::把需要搜索的路径赋值给变量sp,这里举例是c:\tmp
set sp=c:\tmp
::把需要查找的文件名赋值给变量cf,这里举例是root.txt
set cf=root.txt
::把将被替换的字符串赋值给st,这里举例是apple
set st=apple
::把替换字符串赋值给dt,这里举例是lemon
set dt=lemon
[code=BatchFile]
@echo off
::把需要搜索的路径赋值给变量sp,这里举例是c:\tmp
set sp=c:\tmp
::把需要查找的文件名赋值给变量cf,这里举例是root.txt
set cf=root.txt
::把将被替换的字符串赋值给st,这里举例是apple
set st=apple
::把替换字符串赋值给dt,这里举例是lemon
set dt=lemon
@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f %%i in ('dir /b /a:-d *root*.txt') do (
call :replace %%i >%%i.replace
del %%i
ren %%i.replace %%i
)
goto :eof
:replace
for /f "tokens=1,* delims=:" %%j in ('findstr /n ".*" %1') do (
if "%%k"=="" (
echo.
) else (
set tmpline=%%k
set tmpline=!tmpline:-=/!
echo !tmpline!
)
)