Page 1 of 1

[Solved] Is this doable?

Posted: 07 Jun 2011 17:33
by renzlo
Hi Guys,

I was wondering if it's possible to code this situation:

I want to echo this: <Pages>constantnumber_EquipmentLog001.TIF</Pages>

But the scenario is that, that code should be echoed based on the "page range" inputted by the user, for example:

after executing the batch:

Code: Select all

from page: 45 (inputted by the user)
to page: 45 (inputted by the user)

Result: <Pages>constantnumber_EquipmentLog045.TIF</Pages>

or

from page: 45 (inputted by the user)
to page: 46 (inputted by the user)

Result: <Pages>constantnumber_EquipmentLog045 constantnumber_EquipmentLog046.TIF</Pages>

or

from page: 45 (inputted by the user)
to page: 47 (inputted by the user)

Result: <Pages>constantnumber_EquipmentLog045 constantnumber_EquipmentLog046 constantnumber_EquipmentLog047.TIF</Pages>

or

from page: 45 (inputted by the user)
to page: 50 (inputted by the user)

Result: <Pages>constantnumber_EquipmentLog045 constantnumber_EquipmentLog046 constantnumber_EquipmentLog047 constantnumber_EquipmentLog048 constantnumber_EquipmentLog049 constantnumber_EquipmentLog050.TIF</Pages>



Is this possible to code in batch?

Thanks in advance.


-renzlo[b][/b]

Re: Is this doable?

Posted: 07 Jun 2011 17:52
by Cleptography
If you are just looking to echo that line you would

Code: Select all

echo\^<Pages^>constantnumber_EquipmentLog001.TIF^</Pages^>

Re: Is this doable?

Posted: 07 Jun 2011 18:03
by renzlo
clep it is not just echoing the line, you have meet the conditions on page range.

Re: Is this doable?

Posted: 07 Jun 2011 18:25
by Cleptography
Sorry missed that part :oops:
It would take me a min to figure it out as I am not a batch pro.
Truthfully I don't want to at this min.
One of the other experts will be around shortly to help you.

Re: Is this doable?

Posted: 07 Jun 2011 18:38
by renzlo
Yes,i hope that is doable.

Re: Is this doable?

Posted: 07 Jun 2011 18:45
by aGerman
Of course.

Code: Select all

@echo off &setlocal enabledelayedexpansion
set "bTag=<Pages>"
set "eTag=</Pages>"
set "strPart1=constantnumber_EquipmentLog"
set "strPart2=.TIF "
set /p "from=from page: "
set /p "to=to page: "
set /a from+=1000, to+=1000
for /l %%i in (%from%,1,%to%) do (
  set /a x=%%i
  set "innerML=!innerML!%strPart1%!x:~1!%strPart2%"
)
echo(!bTag!!innerML:~,-1!!eTag!
pause

Regards
aGerman

Re: Is this doable?

Posted: 07 Jun 2011 18:59
by renzlo
Perfect aGerman. Thank you always.