如何从Windows批处理代码中的列表/数组访问元素? [英] How can I access an element from a list/array in a windows batch code?
本文介绍了如何从Windows批处理代码中的列表/数组访问元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@echo off
set Counter=0
set folders=(14370437 14707356 16048938 16818856)
for %%f in (*.jpg) do call :p "%%f"
goto :eof
:p
set /a Counter+=1
set /a X=Counter %% 6
%name% = folders[Counter] ???
mkdir C:\output\%name%
if %X%==1 copy %1 C:\output\%name%\front-image.jpg
goto :eof
我有一个静态的文件夹名称列表(该列表比本示例长得多)和另一个需要使用它们的功能.我遍历了一堆.jpg文件,需要将每个文件复制到列表中的下一个文件夹(还要创建该文件夹)
I have a static list of folder names (the list is much longer than this example) and another function where I need to use them. I loop through a bunch of .jpg files and need to copy each one to the next folder in the list (also create the folder)
我找不到按索引从列表(或数组?)文件夹中检索元素的方法.
I couldn't find a way to retrieve an element from the list (or array?) folders, by index.
推荐答案
batch
无法使用列表或数组,但是可以模拟数组:
batch
can't work with lists or arrays, but you can simulate an array:
@echo off
setlocal enabledelayedexpansion
set folders=(14370437 14707356 16048938 16818856)
set i=0
for %%i in %folders% do (
set /a i+=1
set element[!i!]=%%i
)
set element
echo %element[2]%
尽管这可行,但我强烈建议使用它们真正所属的寄生物:
Although this works, I strongly suggest, using the parantheses where they really belong:
@echo off
setlocal enabledelayedexpansion
set folders=14370437 14707356 16048938 16818856
set i=0
for %%i in (%folders%) do (
set /a i+=1
set element[!i!]=%%i
)
set element
echo %element[2]%
set number=3
echo !element[%number%]!
这篇关于如何从Windows批处理代码中的列表/数组访问元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文