[英]Is there any way I can create a string variables with "commas" in batch programme
I am trying to create a variable like this in Batch programme:我正在尝试在批处理程序中创建一个这样的变量:
SET var=abc,def
This command runs fine in command line.此命令在命令行中运行良好。
But when I put same line in a batch file it gives error:但是当我将同一行放在批处理文件中时,它会出错:
def not defined
Is there any other way I can create this string by concatenation or something?有没有其他方法可以通过连接或其他方式创建这个字符串?
I am basically checking for some directories present under current directory and saving names of present directory comma seperated this is what my code looks like我基本上是在检查当前目录下存在的一些目录,并以逗号分隔保存当前目录的名称,这就是我的代码的样子
SET "dirArray=null" IF EXIST dir1 ( IF %dirArray% EQU null ( SET "dirArray=src/main" ) ELSE ( SET "dirArray=%dirArray%,dir1" ) ) ... // further more IF EXIST cases for different directories SET "dirArray=null" IF EXIST dir1 ( IF %dirArray% EQU null ( SET "dirArray=src/main" ) ELSE ( SET "dirArray=%dirArray%,dir1" ) ) ... // 更多 IF EXIST 情况对于不同的目录
@Arescet Has indirectly answered the question http://www.robvanderwoude.com/escapechars.php the above link is list of characters that needs to be escaped , should be escaped as ^, @Arescet 间接回答了问题http://www.robvanderwoude.com/escapechars.php上面的链接是需要转义的字符列表,应该转义为 ^,
so replacing set "dirArray=%dirArray%,dir1" with set "dirArray=%dirArray%^,dir1" works所以用 set "dirArray=%dirArray%^,dir1" 替换 set "dirArray=%dirArray%,dir1" 有效
thanks for the help guys谢谢你们的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.