Home > OS >  A batch of how to assign multiple values to a variable
A batch of how to assign multiple values to a variable

Time:11-11

Such as I want to use the batch implement such a demand, the current folder obj files are assigned to a variable, such as D: \ work under a a.o bj, b.o bj and c.o bj etc. Multiple files, now the traverse D: \ work this folder, all the OBJS obj file path are given, finally the value of the output OBJS is OBJS=D: \ work \ a.o bj D: \ work \ b.o bj D: \ work \ c.o bj

Code is roughly as follows:
 
The set OBJS=
For/r./% % a in (*. Obj) do (
The set OBJS "OBJS=% % % % a"
)
Echo OBJS % %


But the code does not achieve this effect,

CodePudding user response:

The building Lord reference under this post "batch how to use a for loop to multiple values assigned to variables"
https://zhidao.baidu.com/question/437608909787039844.html

CodePudding user response:

reference 1st floor nettman response:
your reference under this post "batch how to use a for loop to multiple values assigned to multiple variable"
https://zhidao.baidu.com/question/437608909787039844.html


Warrior, what you say to a single variable assigned a value, the main problem is how multiple values pieced together,

CodePudding user response:

Find the right way, the code is as follows:

 
@ echo off
SETLOCAL EnableDelayedExpansion
The set OBJS=
For/r./% % a in (*. Obj) do (
Set "OBJS=! OBJS! % % a "
)
Echo OBJS % %

CodePudding user response:

Reference:

How, in the for loop variable loop variable assignment to a variable batch bat

CodePudding user response:

Search: batch string concatenation

CodePudding user response:

reference 5 floor ziqi0716 reply:
search: batch string concatenation


This patchwork is not string,

CodePudding user response:

OBJS=D: \ work \ a.o bj D: \ work \ b.o bj D: \ work \ c.o bj
This is not a a.o bj, b.o bj, c.o bj three files of the full path name string literals are concatenated with Spaces up results?

CodePudding user response:

refer to the second floor clever101 response:
Quote: refer to 1st floor nettman response:
your reference under this post "batch how to use a for loop to multiple values assigned to multiple variable"
https://zhidao.baidu.com/question/437608909787039844.html


Warrior, what you say to a single variable assigned a value, the main problem is how pieced together multiple values,


Dizzy, see the wrong post content
  • Related