Page 1 of 1
Rename xml file based on the content inside using window bat
Posted: 23 Jan 2015 03:44
by rams1986
Hi Folks,
I have an requirement using windows batch scripting.Im very new to this so kindly help me out.
I have multiple xml files , ex APJ01.xml,APJ02.xml...APJ0N.xml. Now based on the content inside the file i need to rename these xmlfiles with corresponding value init. exmaple
<SalesOrder><SOM_SalesOrderID>976064101</SOM_SalesOrderID>
current xml file name : APJ01.xml
after renaming :: APJ_976064101_timestamp.xml.
Please help me doing this in windows batch. i have to do only in windows batch.
Re: Rename xml file based on the content inside using window
Posted: 23 Jan 2015 07:10
by Squashman
This question has been discussed several times over the years on this forum. Will try and dig up the threads for you.
Re: Rename xml file based on the content inside using window
Posted: 23 Jan 2015 07:42
by ShadowThief
CSV.bat will surely help with this.
Re: Rename xml file based on the content inside using window
Posted: 23 Jan 2015 08:02
by Squashman
ShadowThief wrote:CSV.bat will surely help with this.
IMHO I don't think it will.
Penpen wrote a XML parsing routine. Just need to find the thread.
Re: Rename xml file based on the content inside using window
Posted: 23 Jan 2015 19:25
by foxidrive
Test this in a folder with some files.
It will write
tempren.bat with the rename commands inside it for you to check.
The helper batch file
repl.bat is a plain batch file too.
Code: Select all
@echo off
(
for %%a in (*.xml) do (
type "%%a"|repl ".*<SalesOrder><SOM_SalesOrderID>(.*?)</SOM_SalesOrderID>.*" "ren \q%%a\q \q<%%a<_$1_timestamp%%~xa\q" xia|repl "(.*)<(...).*<(.*)" "$1$2$3" a
)
)>tempren.bat
This uses a helper batch file called `repl.bat` (by dbenham) - download from:
https://www.dropbox.com/s/qidqwztmetbvklt/repl.batPlace `repl.bat` in the same folder as the batch file or in a folder that is on the path.
Re: Rename xml file based on the content inside using window
Posted: 25 Jan 2015 18:21
by penpen
Squashman wrote:Penpen wrote a XML parsing routine. Just need to find the thread.
I've found it:
http://www.dostips.com/forum/viewtopic.php?p=32941#p32941The first code block contains an example on how to extract data from a xml file using xslt.
The second code block contains the file "xslt.bat".
penpen