Page 1 of 1

advanced batch problem

Posted: 09 Oct 2009 07:45
by sysadmin
Hi there,

I'm looking for an advanced batch.

I have a folder with xml files. In the content of these files there is a unique customername.

What i would like is to have a batch file that crawls through the folder and find the customername in the xml file.
If the name is found, the file should be moved to a new folder. This folder must be the name that is found as customername.
If the folder doesn't exist, the folder must be created first, en then move the file into this folder.

As you probably guess, the customername isn't the same in all xml files, but consist out of 8 or 10 letters/numbers

Can anybody help me out please.

Kind regards,

Edwin.

Posted: 09 Oct 2009 11:30
by avery_larry
We'd need an example of the xml file. We need to know how the unique customername can be indentified in the file (ex. -- is there always a line that says customername=xxyy1212).

Once we know that, a variety of for loops and find statements should get the job done.

Posted: 10 Oct 2009 11:02
by sysadmin
avery_larry

Thanks for your reply.
I've found something that worked for me.

Here is the code:

@echo off
for /f "delims=" %%f in ('dir /b *.xml') do (
FOR /F "tokens=2 delims=><" %%i in ('findstr "<name>" %%f') do (
mkdir %%i
move %%f %%i )
))