Someone please help...oh, I will be so grateful. I have a very long batch file that is working perfectly except that every time the user enters input, it replaces strings in the
It's an effect of delayed expansion and the batch parser.
If delayed expansion is disabled there aren't problems with exclamation marks, but if it's enabled the parser suppose that the !
are for expanding a variable, and when there is only one mark, it will be dropped.
So the solution is to disable delayed expansion, but as you need it, you must enable it too!
This can be done with simply toggling it in the right moment.
setlocal DisableDelayedExpansion
(
for /F "usebackq delims=" %%a in ("%drive%:\mckesson\%bdi1%\importer.config") do (
set "str=%%a"
setlocal EnableDelayedExpansion
set "str=!str:server_name=%server%!"
set "str=!str:bdi_name=%bdi1%!"
set "str=!str:share_name=%share%$!"
set "str=!str:drive_bdi=%drive%!"
echo(!str!
endlocal
)
) > newfile.txt
I move the rediretion to the complete FOR-block, it's faster and you don't need to delete the file first.
I try to move all your replacements into one block, so you only need to read the file only once.