【发布时间】:2015-11-12 19:36:16
【问题描述】:
我对@987654321@ 比较陌生,我正在尝试创建一个 Windows 批处理文件,该文件将一组中的静态数组值与另一组中的静态数组值重命名 - 移动到另一个文件夹。像这样的:
setlocal EnableDelayedExpansion
set currentDate=%date:~-4,4%%date:~-10,2%%date:~-7,2%
set fromPath=C:\
set toPath=C:\Temp\
set fileList=(temp1.txt temp2.txt temp3.txt)
set toList=(name1 name2 name3)
我正在研究这种样式的数组,因为它看起来更容易让用户将其添加到列表中。
单独(没有 toList)fileList 工作正常:
for %%i in %fileList% do (
IF EXIST %FromPath%%%i
ren %FromPath%%%i %%~ni_%currentDate%%%~xi &
move %FromPath%%%~ni_%currentDate%%%~xi %toPath%
)
但显然这不会按照与toList 中的列表相同的顺序从toList 重命名。
我尝试了带有这样索引的计数器的代码(也尝试了下面的其他变体)但没有运气:
for /L %%i IN (0,1,10) DO (
IF EXIST %FromPath%%fileList[%%i]%
ren %FromPath%%%i %%~ni_%currentDate%%%~xi &
move %FromPath%%%~ni_%currentDate%%%~xi %toPath%
)
这样的事情可能吗?如果没有,我愿意接受上述任何其他建议。
提前致谢!
【问题讨论】:
标签: arrays windows file batch-file for-loop