I am trying to replace some values at once (red ones) with each file's name in several .xml files inside a directory.
Example:
File name = 20181105abc.xml
<id>abcdef</id> <-- 20181105abc.xml
<city>London</city>
<country>UK</country>
<year>2018</year>
<type>Business trip</type>
<fileid>123456</fileid> <-- 20181105abc.xml
The batch script i've found so far and still testing is as below:
Code: Select all
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "replace=id"
set "replace2=fileid"
for %%P in ("*.xml") do (
for /F "delims=" %%I in ('
findstr /N /R "^" "%%~P" ^& ^> "%%~fP" break
') do (
set "LINE=%%I"
setlocal EnableDelayedExpansion
set "LINE=!LINE:*:=!"
if defined LINE set "LINE=!LINE:%replace%=%replace%%%~nP</%replace%>!"
if defined LINE set "LINE=!LINE:%replace%=%replace2%%%~nP</%replace2%>!"
>> "%%~fP" echo(!LINE!
endlocal
)
)
endlocal
exit /B
Any suggestions are welcome.