I am trying to create a .bat script that goes into each subfolder in a folder and replaces a value in an .xml file based on the subfolders name. I believe I am quite close with the following:
@echo off
for /d %%i in ("E:\working\test\tmp\*") do (
set "replaced=different"
setlocal enableDelayedExpansion
cd /d "%%i\word\"
@echo on
for /f "tokens=* delims= " %%a in (document.xml) do (
set "line=%%a"
set "line=!line:placeholder=%replaced%!"
echo !line!>>new.txt
)
)
endlocal
pause
The code above produces the result:
document.xml contents= "testplaceholdertest"
new.txt contents = "testtest"
I think the issue is with this line:
set "line=!line:placeholder=%replaced%!"
I don't think it is setting or using the %replaced% variable correctly, I could use %%~ni but I need to modify the name a little before replacing, hence why I need a variable to work. Anyone know why or how I would fix it?