本文介绍了如何通过批量阵列循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个这样的数组:
I created an array like this:
set sources[0]="\\sources\folder1\"
set sources[1]="\\sources\folder2\"
set sources[2]="\\sources\folder3\"
set sources[3]="\\sources\folder4\"
现在我想通过这个数组迭代:
Now I want to iterate through this array:
for %%s in (%sources%) do echo %%s
它不工作!看来,剧本是不会进入循环。这是为什么?我如何可以循环呢?
It doesn't work! It seems that script is not going into the loop. Why is that? How can I iterate then?
推荐答案
如果你不知道数组有多少元素有(似乎是这样),你可以使用这个方法:
If you don't know how many elements the array have (that seems is the case), you may use this method:
for /F "tokens=2 delims==" %%s in ('set sources[') do echo %%s
请注意,该元素将被处理的按字母顺序排列的,也就是说,如果你有超过9(或99等)的元素,该指数必须留在元素零(S)1 ..9(或1..99等)
Note that the elements will be processed in alphabetical order, that is, if you have more than 9 (or 99, etc) elements, the index must have left zero(s) in elements 1..9 (or 1..99, etc.)
这篇关于如何通过批量阵列循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!