Batch Programming: read txt and keep variables with a subroutine -


i writing bactch-file first time , have problem couldn't solve yet. (i'm not programmer mechanical engineer, please forgive me clumsiness.. , english: i'm not native speaker...)

i want write batch file (readlist.bat) amongst other things should read in txt-file (text.txt). batch-file should able called in batch file "call readlist.bat". clear me following: have define variables within readlist.bat not locally if want them stored after readlist.bat finishes. tried realize in attached files @ least of variables. (of course final goal keep variables read in txt-file.) cant manage this.

the text.txt contains "test variables" readlist.btat should read in rows in columns (this works). variables need defined "not locally". therefore testing reasons added following commands:

endlocal   set "job1fld=%job1fld%"   set "job1dat=%job1dat%"   set "job1kyw=%job1kyw%"   set "job2fld=%job2fld%"   set "job2dat=%job2dat%"   set "job2kyw=%job2kyw%"   set "job3fld=%job3fld%"   set "job3dat=%job3dat%"   set "job3kyw=%job3kyw%"    set vartest1=test1   set vartest2=test2   set vartest3=test3   set vartest4=test4   set vartest5=test5   set vartest5=test6   set vartest6=test7  

the second block seems work. or lets say: variables handed on callreadlist. manually set test-variables...

the first block doesn't work , can't figureout why...

how manage variables read in kept after readlist.bat finishes? because absolute greenhorn when comes batch-files, glad if don't give me tipps codes ;-)

thank in advance.

roy

callreadlist.bat:

@echo off call readlist.bat set pause 

readlist.bat:

rem ================================= rem ================================= rem read txt @echo off setlocal enabledelayedexpansion rem start: read 1. column (ordner) set colno=1 set cntr1=0 /f "delims=; tokens=%colno%" %%a in (text.txt) (     set /a cntr1=!cntr1! + 1     set job!cntr1!fld=%%a ) rem end: read 1. column (ordner) rem start: read 2. column (ordner) set colno=2 set cntr2=0 /f "delims=; tokens=%colno%" %%a in (text.txt) (     set /a cntr2=!cntr2! + 1     set job!cntr2!dat=%%a ) rem end: read 2. column (ordner) rem start: read 3. column (ordner) set colno=3 set cntr3=0 /f "delims=; tokens=%colno%" %%a in (text.txt) (     set /a cntr3=!cntr3! + 1     set job!cntr3!kyw=%%a ) rem end: read 3. column (ordner) endlocal set "job1fld=%job1fld%" set "job1dat=%job1dat%" set "job1kyw=%job1kyw%" set "job2fld=%job2fld%" set "job2dat=%job2dat%" set "job2kyw=%job2kyw%" set "job3fld=%job3fld%" set "job3dat=%job3dat%" set "job3kyw=%job3kyw%" set vartest1=test1 set vartest2=test2 set vartest3=test3 set vartest4=test4 set vartest5=test5 set vartest5=test6 set vartest6=test7 

txt-file:

ordner1;job1;input1 ordner2;job2;input2 ordner3;job3;input3 ordner4;job4;input4 ordner5;job5;input5 ordner6;job6;input6 ordner7;job7;input7 ordner8;job8;input8 ordner9;job9;input9 ordner10;job10;input10 ordner11;job11;input11 ordner12;job12;input12 ordner13;job13;input13 ordner14;job14;input14 ordner15;job15;input15 ordner16;job16;input16 ordner17;job17;input17 ordner18;job18;input18 ordner19;job19;input19 ordner20;job20;input20 ordner21;job21;input21 ordner22;job22;input22 ordner23;job23;input23 ordner24;job24;input24 ordner25;job25;input25 ordner26;job26;input26 ordner27;job27;input27 ordner28;job28;input28 ordner29;job29;input29 ordner30;job30;input30 ordner31;job31;input31 ordner32;job32;input32 ordner33;job33;input33 ordner34;job34;input34 ordner35;job35;input35 ordner36;job36;input36 ordner37;job37;input37 ordner38;job38;input38 ordner39;job39;input39 

nice stuff:

@echo off /f %%a in ('^< text.txt find /c /v ""') set /a lines=%%a <text.txt ( /l %%a in (1 1 %lines%) (     set "line="     set /p "line="     /f "tokens=1-3delims=;" %%d in ('call echo %%line%%') (         set "job%%afld=%%d"&set "job%%asat=%%e"&set "job%%akyw=%%f"     ) )) set "line="&set "lines=" set "job" 

this easy, real challenge give each job-variable unique number (here 1-117) without delayed expansion.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -