|
Answer» I've been throwing myself at this all evening but am only making baby steps with my BAT file, so I thought I'd put this before the collective and see if anyone can point me in the right direction.
I am trying to generate 800+ XML files with almost identical data except for two lines whose number will increment. This BAT file will then save the XML with a similarly incremented file name. Here is a sample of the XML (which I've already escaped the < and > )
^ ^93798^ ^ ^ ^Patient^ ^Generic^ ^M^ ^000-00-0001^ ^000-00-0001^
I am struggling to rap my head around incrementing both of the instances of 000-00-0001 (and really, only the final 3 digits need to increment) as well as then increment the resulting XML file name.
Any suggestions would be welcome.
Well, I did it... This is horribly sad work, but it does what I need... Code: [Select]@echo off :start setlocal EnableExtensions EnableDelayedExpansion set /a num=%num% + 0001 (echo ^<qe:message_id/^> echo ^<qe:billing_code^>93798^</qe:billing_code^> echo ^<qe:order_number/^> echo ^<qe:patient_account_number/^> echo ^<qe:patient_last_name^>Patient^</qe:patient_last_name^> echo ^<qe:patient_first_name^>Generic^</qe:patient_first_name^> echo ^<qe:patient_middle_name^>M^</qe:patient_middle_name^> echo ^<qe:patient_mrn^>000-00-!num!^</qe:patient_mrn^> ) >> output!num!.xml goto start endlocalThis is what your first xml will look like.
Code: [Select]<qe:message_id/> <qe:billing_code>93798</qe:billing_code> <qe:order_number/> <qe:patient_account_number/> <qe:patient_last_name>Patient</qe:patient_last_name> <qe:patient_first_name>Generic</qe:patient_first_name> <qe:patient_middle_name>M</qe:patient_middle_name> <qe:patient_mrn>000-00-1</qe:patient_mrn> Note the number is 000-00-1. Is that really what you want? (Didn't you show that number padded with zeros to make it 4 CHARACTERS wide?) Also where is the patient_ssn line?
Also, move the setlocal line above the :start label, otherwise you will get this error:
Maximum setlocal recursion level reached. Maximum setlocal recursion level reached. Maximum setlocal recursion level reached. Maximum setlocal recursion level reached. Maximum setlocal recursion level reached. (etc)
Finally, before you can stop the thing, you are going to have a LOT of files.
What I suggest is something like this
Code: [Select]@echo off setlocal EnableExtensions EnableDelayedExpansion
REM Change these to what you want set startnum=1 set endnum=800 set numstep=1
for /L %%N in (%startnum%, %numstep%, %endnum%) do (
set formattednumber=0000%%N set formattednumber=!formattednumber:~-4!
(
echo ^<qe:message_id/^> echo ^<qe:billing_code^>93798^</qe:billing_code^> echo ^<qe:order_number/^> echo ^<qe:patient_account_number/^> echo ^<qe:patient_last_name^>Patient^</qe:patient_last_name^> echo ^<qe:patient_first_name^>Generic^</qe:patient_first_name^> echo ^<qe:patient_middle_name^>M^</qe:patient_middle_name^> echo ^<qe:patient_mrn^>000-00-!formattednumber!^</qe:patient_mrn^> echo ^<qe:patient_ssn^>000-00-!formattednumber!^</qe:patient_ssn^>
) >> output!formattednumber!.xml
)
output like this
Code: [Select]<qe:message_id/> <qe:billing_code>93798</qe:billing_code> <qe:order_number/> <qe:patient_account_number/> <qe:patient_last_name>Patient</qe:patient_last_name> <qe:patient_first_name>Generic</qe:patient_first_name> <qe:patient_middle_name>M</qe:patient_middle_name> <qe:patient_mrn>000-00-0001</qe:patient_mrn> <qe:patient_ssn>000-00-0001</qe:patient_ssn>Explanatory:
@echo off REM You need delayed EXPANSION in the loop setlocal EnableExtensions EnableDelayedExpansion
REM Change these to what you want set startnum=1 set endnum=800 set numstep=1
REM FOR /L syntax: for /L %%X in (start, step, end) do REM in this loop, the %%variable will be assigned each numerical value starting at start, INCREASING by step and ending at end REM examples: REM for /L %%A in (1,2,11) will give ascending odd numbers 1 to 11 REM for /L %%Y in (100,-1,1) will give descending numbers from 100 to 1
for /L %%N in (%startnum%, %numstep%, %endnum%) do (
REM How to pad the number (or any other string) REM add some zeroes or other characters such as dots or spaces to the left of the number set formattednumber=0000%%N
REM We the use the final X characters from the right hand side REM here X is 4 set formattednumber=!formattednumber:~-4!
)
|