【发布时间】:2018-02-05 14:43:53
【问题描述】:
我写了一个在文件名流中循环的简单脚本,我得到了 从 dir 命令通过管道传输,后跟此 url For /F command:
FOR /F "tokens=*" %%G IN ('dir /b ^"???? *.sql^"') do (
call :runscript "%%G" %dbname% %op% %dbinstance%
rem stop further processing if execution failed and return error code
if errorlevel 1 exit /b 1
)
不幸的是,我收到了这个错误:
错误 'dir /b "???? *.sql"' 不被识别为内部或 外部命令、可运行程序或批处理文件。
【问题讨论】:
-
将
^左移至"。仅|、&、>必须在 FOR 在以cmd.exe /C和指定命令行启动的后台进程中执行的 DIR 命令行中进行转义. -
在这种情况下不需要使用
FOR /F。您可以只使用基本的FOR命令。FOR %%G IN ("???? *.sql") do (
标签: batch-file for-loop cmd directory