Почему мой for работает в командной строке, но не в моем пакетном скрипте

#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. Потому что вы не прочитали файл справки для используемой вами команды. Вам потребовалось бы всего 15 секунд, чтобы прочитать, как это указано в верхней части файла справки. To use the FOR command in a batch program, specify %%variable instead of %variable.

Ответ №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.