【发布时间】:2014-06-14 14:34:52
【问题描述】:
以此为例 For statement in batch script from SO
尝试了以下
for %%f in (c:\username\desktop\Test\*.log) do (
echo %%~nf
)
我收到以下错误:%%f was unexpected at this time
我的目标是将 [n] 个文件从一个目录移动到另一个目录,等待 [x] 秒,然后移动下 [n] 个文件
我可以通过对未知站点执行 ping 并强制延迟或使用超时来等待时间 [尚未测试,因为这需要在没有任何用户干预的情况下完成]
如果有更好的方法来做到这一点,我很开放,因为这是我第一次尝试这种类型的脚本。
【问题讨论】:
-
您的问题“%%f was unexpected...”是由于尝试直接从提示符执行批处理命令引起的。您需要将文本保存在名为 somethingorother.bat 的文件中 - .bat 是关键。然后通过在提示符处输入 somethingorother 来执行 somethingorother.bat;然后选择并运行 .bat 文件。当然比永远重新输入命令行更容易。如果您明确希望直接从提示符运行,请将 元变量(循环控制变量)中的任何
%%x减少为%x
标签: windows batch-file command-line