为什么我的工作在命令行而不是我的批处理脚本

时间:2016-10-13 12:31:36

标签: batch-file

当我在cmd.exe中运行以下行时,它会起作用。

FOR /d /r ./ %d IN (*Images) DO @IF EXIST "%d" RD /s/q "%d"

当我在我的批处理脚本中粘贴相同的行时,它说:

d" RD /s/q "d" was unexpected at this time.

1 个答案:

答案 0 :(得分:1)

要在批处理程序中使用FOR命令,请指定%%variable而不是%variable

for /?在第一个屏幕(第9行)上说:

==> for /?
Runs a specified command for each file in a set of files.

FOR %variable IN (set) DO command [command-parameters]

  %variable  Specifies a single letter replaceable parameter.
  (set)      Specifies a set of one or more files.  Wildcards may be used.
  command    Specifies the command to carry out for each file.
  command-parameters
             Specifies parameters or switches for the specified command.

To use the FOR command in a batch program, specify %%variable instead
of %variable.  Variable names are case sensitive, so %i is different
from %I.