Problems with variables ...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
JamesJayceJohn
Posts: 2
Joined: 19 Nov 2018 14:55

Problems with variables ...

#1 Post by JamesJayceJohn » 19 Nov 2018 15:29

Hi
I have two files
The first is batch.ini and the second is batch.bat
I would like the string retrieved by the bat in the ini file display the variables defined in bat file.
With the following code, it does not work.
The string of characters retrieved does not display the variables defined in the bat file.
echo %csvchoice% --> %var1%;%var2%;%var3%
I am looking for the following result:
echo %csvchoice% --> James;Jayce;John

Thanks for your help

Batch.ini file:

Code: Select all

csvchoice=%var1%;%var2%;%var3%
Batch.bat file:

Code: Select all

set var1=James
set var2=Jayce
set var3=John

Define.Csvchoice.Ini

for /F "tokens=* delims= " %%f in ('findstr /R /C:"csvchoice=" batch.ini') do (
    
    
    set csvchoice_ini=%%f
    goto :End.Csvchoice.Ini
)

:End.Csvchoice.Ini


set csvchoice=%csvchoice_ini:~10%
echo Variable in batch.bat : %var1%;%var2%;%var3%
echo Variable in batch.ini : %csvchoice%

pause

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Problems with variables ...

#2 Post by aGerman » 20 Nov 2018 10:57

Try

Code: Select all

call set "csvchoice_ini=%%f"
Steffen

JamesJayceJohn
Posts: 2
Joined: 19 Nov 2018 14:55

Re: Problems with variables ...

#3 Post by JamesJayceJohn » 20 Nov 2018 12:22

It's perfect !!

Thanks for this really quick help

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Problems with variables ...

#4 Post by Squashman » 20 Nov 2018 13:50

If csvchoice is only present once in your INI file then there is no need for the GOTO command.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Problems with variables ...

#5 Post by Ed Dyreen » 21 Nov 2018 08:08

Squashman wrote:
20 Nov 2018 13:50
If csvchoice is only present once in your INI file then there is no need for the GOTO command.
And if unique identifiers are used then you can just

Code: Select all

<:unique_id <nul rem^ &for %%? in ( condition ) do if %%?==condition goto :unique_id
echo.previous loop aborted.
:End.Csvchoice.Ini, these are typically the types of labels I would never name with a unique identifier because the label does nothing more than abort a loop and is not used as the name of a function. If any label used at all I'd use one that is generic and implies it's purpose like :skip

Code: Select all

for %%? in ( condition ) do if %%?==condition goto :skip
:skip
echo.we skipped once

for %%? in ( condition ) do if %%?==condition goto :skip
:skip
echo.we skipped twice
you can have as many labels with the same name as you like, because goto doesn't jump upwards unless the end of file is reached which should be avoided in this case.

Post Reply