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.
Rename xml file based on the content inside using window bat
Moderator: DosItHelp
Re: Rename xml file based on the content inside using window
This question has been discussed several times over the years on this forum. Will try and dig up the threads for you.
-
- Expert
- Posts: 1160
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Rename xml file based on the content inside using window
CSV.bat will surely help with this.
Re: Rename xml file based on the content inside using window
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
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.
This uses a helper batch file called `repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
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.bat
Place `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
I've found it: http://www.dostips.com/forum/viewtopic.php?p=32941#p32941Squashman wrote:Penpen wrote a XML parsing routine. Just need to find the thread.
The 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