简体   繁体   English

有什么方法可以在批处理程序中创建带有“逗号”的字符串变量

[英]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.

相关问题 在批处理文件中,如何将一串值分配给变量列表? - In a batch file, how can I assign a string of values to a list of variables? 我如何用其他方式写它? (批量) - How i can write it in a different way? (batch) 如何通过另一个程序访问Windows服务对象 - How Can I access Windows Service Object by Another Programme 如何在具有一系列变量的批处理文件中循环执行一组命令? - How can I loop a set of commands in a batch file with a series of variables? 将字符串解析为变量批处理脚本 - Parsing a string into variables batch script 我已经尝试了几乎所有可以从 web 中找到的东西。 没有什么。 有没有办法合并一个字符串和一个变量,批量打开一个程序? - I've tried almost everything I could find off the web. Nothing. Is there any way to merge a string and a variable, to open a program in batch? 如何创建更改我的 MAC 地址的批处理文件? - How can I create a batch file that changes my MAC address? 批处理:如何在快捷方式不存在时创建快捷方式 - Batch : How can I create a shortcut when it does not exist 如何使用Taskkill为批处理文件创建输入提示 - How can I create an input prompt for batch file using taskkill 我可以创建一个只提取几个 IP 之一的批处理程序吗? - Can I create a batch program that extracts only one of several IP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM