2016-10-13 101 views
0

当我在cmd.exe CONSOL中运行以下行它的工作原理。为什么我的命令行工作,但不是我的批处理脚本

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

当我粘贴到我的批处理脚本在同一行,它说:

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

因为你没看过你正在使用的命令的帮助文件。这会让你花15秒钟阅读,因为它位于帮助文件的顶部。 '要在批处理程序中使用FOR命令,请指定%%变量而不是%变量。 ' – Squashman

回答

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. 
相关问题