advanced batch problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sysadmin
Posts: 2
Joined: 09 Oct 2009 07:32

advanced batch problem

#1 Post by sysadmin » 09 Oct 2009 07:45

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.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 09 Oct 2009 11:30

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.

sysadmin
Posts: 2
Joined: 09 Oct 2009 07:32

#3 Post by sysadmin » 10 Oct 2009 11:02

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 )
))

Post Reply