如何使用 bat 脚本将命令表达式的结果存储在变量中? [英] How to store the result of a command expression in a variable using bat scripts?
本文介绍了如何使用 bat 脚本将命令表达式的结果存储在变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的命令来计算所有遵循 20??????
模式的目录:
I have the command below to count all directories that that follow the pattern 20??????
:
'dir /b "20??????" | find /c "2"'
例如,如果我有以下目录,命令将返回 6:
For example, if I have the following directories, the command would return 6:
20090901
20090902
20090903
20090904
20090905
20090906
如何将这个命令的结果(前面提到的例子中的 6)存储在一个变量中?
How can I store the result of this command (6 in the forementioned example) in a variable?
推荐答案
set cmd="dir /b "20??????" | find /c "2" "
FOR /F "tokens=*" %%i IN (' %cmd% ') DO SET X=%%i
这篇关于如何使用 bat 脚本将命令表达式的结果存储在变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文