2

I have an xml file with the following:

<setParameter value="\\deveserver\d$\Websites\anime" name="IIS Web Application Name"/>

I want to write a batch script that will search for this \\deveserver\d$\Websites\anime string (which is saved in a variable, called CurrentFolder) and replace it with whatever input that was entered.

I saved the entered path in variable, DestinationFolder

SET DestinationFldr=
SET /p DestinationFldr=Enter Destination path:

Any replace and text posts that I checked doesn't seem to work. I think it's not able to recognize the double backslash. Please help. Thanks.

2 Answers 2

1
@ECHO off
SETLOCAL
SET "currentfolder=\\deveserver\d$\Websites\anime"
SET "DestinationFldr=some\variety\of\input"
(
FOR /f "delims=" %%i IN ('type aninput.xml^|findstr /n /r "$" ') DO (
 SET line=%%i
  SETLOCAL ENABLEDELAYEDEXPANSION
  SET line=!line:*:=!
  IF DEFINED line (ECHO(!line:%currentfolder%=%destinationfldr%!) ELSE (ECHO()
  endlocal
)
)>anoutput.xml

FC aninput.xml anoutput.xml

Setting currentfolder as specified and destfldr to some string to simulate input,

  • read each line into %%i and number it with leading number : - including empty lines
  • assign the value to line
  • start a setlocal delayedexpansion frame
  • remove the part of line up to and including the first colon (ie the line number inserted by findstr
  • if line is still defined, echo it with the string substituted; else echo a blank line
  • close the setlocal frame

FC inputfile outputfile to show changes

Sign up to request clarification or add additional context in comments.

1 Comment

@user2283170 If that worked for you, it is expected that you will upvote the answer and then "accept" it (click the check-mark below the votes).
0

If you have <setParameter value="\\deveserver\d$\Websites\anime" name="IIS Web Application Name"/> in file.xml you can use this code:

@echo off&setlocal
set "CurrentFolder=\\deveserver\d$\Websites\anime"

for /f "delims=" %%i in (file.xml) do set "html=%%i"
SET DestinationFldr=
SET /p "DestinationFldr=Enter Destination path: "
setlocal enabledelayedexpansion
set "html=!html:%CurrentFolder%=%DestinationFldr%!"
echo html: !html!

Test & output:

Enter Destination path: \\myserver\&&\othersites\adele
html: <setParameter value="\\myserver\&&\othersites\adele" name="IIS Web Application Name"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.