在命令行脚本中使用迭代变量创建文件名
我正在尝试使用批处理文件自动执行adb测试过程。在每次运行一个文件之后,制作.CloudData.txt
。我想前言该文件名与审判数量,T1.CloudData.txt
,等我做了这个测试代码:在命令行脚本中使用迭代变量创建文件名
echo off
set /p loops="Enter a number of iterations: "
for /l %%i in (1,1,%loops%) do (
set file=//scard//mytest//T%%i.CloudData.txt
echo %file%
)
,最终使我能有沿着线的东西:
echo off
set /p loops="Enter a number of iterations: "
for /l %%i in (1,1,%loops%) do (
rem Execute adb commands for test
set file=//scard//mytest//T%%i.CloudData.txt
adb shell mv /sdcard/mytest/.CloudData.txt file
)
但测试返回,假设loops
= 3,/sdcard/mytest/T3.CloudData.txt
3次。具体而言,存储在loops
中的号码正在被添加,其中%%i
应该是。从我在下面的文章中看到的:bash script variable inside variable,我想我应该使用一个数组,但是如果有一天我必须运行测试的次数超过迭代次数而不是数组允许的话,这是不切实际的。我应该如何继续?
echo off
setlocal enabledelayedexpansion
set /p loops="Enter a number of iterations: "
for /l %%i in (1,1,%loops%) do (
rem Execute adb commands for test
set file=//scard//mytest//T%%i.CloudData.txt
adb shell mv /sdcard/mytest/.CloudData.txt !file!
)
原因%%i
似乎3
在所有三次(它不是)是可变%file%
,这是从你的脚本上次运行留下
非常感谢!如果你不介意,你能解释一下调用'!file !'与调用'%file%'有什么不同吗? – alwaysthestudent
@alwaysthestudent请阅读第一个批次问题[delayedexpansion](https://ss64.com/nt/delayedexpansion.html)最艰苦的研究工作将揭示这一点。 – LotPings
感谢资源,它很有启发性;我很抱歉浪费你的时间。 – alwaysthestudent
只需注意:这不是PowerShell,而是实际的Command Shell。你应该编辑你的标题和标签,将你的问题提交给合适的人! –
谢谢!抱歉给你带来不便。 – alwaysthestudent
这不是*** ***,*** *** ***。我会解决它。 –