在命令中使用括号批处理循环

时间:2021-09-30 00:37:47

I have a batch file with the following code:

我有一个包含以下代码的批处理文件:

for /f "tokens=*" %%a in ('dir /b /a-d') do (
 echo Processing %%a >>%LOG%
 dtsrun /S(local) /NNotesLoad /A"FilePath:8="%NOTESDIR%\%%a" /AClientID=%1 >>%LOG%

 echo Deleting %%a >>%LOG%
 del %%a /q
)

This is returning an error message of "/NNotesLoad was unexpected at this time" because the second bracket is effectively closing the FOR block.

这将返回“/ NNotesLoad此时出乎意料”的错误消息,因为第二个括号正在有效地关闭FOR块。

I have to leave the (local) as the /S parameter.
How do I escape the brackets in the dtsrun line?

我必须将(local)保留为/ S参数。如何从dtsrun行中删除括号?

EDIT: Turns out you can specify the server in dtsrun for local as .

编辑:结果你可以在dtsrun中为本地指定服务器。

But I would still like an answer to the escaping for the brackets.

但我仍然想要回答括号中的问题。

1 个解决方案

#1


The solution for escaping the brackets characters is to prefix with a caret ^

转义括号字符的解决方案是使用插入符号前缀^

So it would read:

所以它会读:

/S^(local^)

#1


The solution for escaping the brackets characters is to prefix with a caret ^

转义括号字符的解决方案是使用插入符号前缀^

So it would read:

所以它会读:

/S^(local^)