2016-10-13 100 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. 
相關問題