Page 1 of 1

Batch - extracting names from file to draw

Posted: 2011-03-29T09:53:31-07:00
by michal13
I would like to solve this thema:
I have for example
.jpg files (1.jpg - n.jpg)

and

list.txt written as follows:
1¦name_1
2¦name_2
....
n¦name_n

I want to draw names from this list.txt file to single pictures (1.jpg annotate with name_1 and so on).

I tried to use this batch, but it reads just last name:
-------------------------------------------------------------
set %sc=0
for %%f in (*.jpg) do (
set /a %sc=sc+1
)
set %lv=0

:begin
set /a %lv=lv+1
for /f "delims=¦ tokens=2 skip=%lv%" %%A in (list.txt) do (convert -fill yellow -pointsize 20 -gravity south -draw "text 0,4 '%%A' " %lv%.jpg c%lv%.jpg)
if %lv% equ %sc% goto enddir
goto begin
:enddir
-------------------------------------------------------------
Can You help me?
Thanx
Michal

Re: Batch - extracting names from file to draw

Posted: 2011-03-29T11:11:10-07:00
by el_supremo
When DOS reads your FOR statement it sets all the variable ONCE. You have to set delayed variable expansion so that it sets them each time through the loop and then eac hvariable that must be delayed must be enclosed in !..! instead of %..% (dontcha just love DOS batch syntax? :-( )
Delayed expansion is turned on with this command:
SETLOCAL EnableDelayedExpansion
In your case I presume you will need to use !lv! in the loop instead of %lv%

Pete

Re: Batch - extracting names from file to draw

Posted: 2011-03-29T15:09:53-07:00
by michal13
Thank You Pete,
I found it! You gave me courage to test other ways, this one is running:

set %sc=0
for %%f in (*.jpg) do (
set /a %sc=sc+1
)
set %lv=0

:begin
set /a lv=lv+1

FOR /F "delims=¦ tokens=2 skip=%lv%" %%A in (list.txt) do (c -fill red -pointsize 20 -gravity south -draw "text 0,4 '%%A' " %lv%.jpg c%lv%.jpg
if %lv% equ %sc% goto enddir
goto begin
)

:enddir

Hours of time are saved.. :wink:
Unfortunatelly I don’t manage Perl or something better than DOS :-/
Good Luck!
Michal
arboretum.mendelu.cz/rs/obrazek.pl?id=9942