我有这个代码:
setlocal enableextensions
for "usebackq" %%i in (`dir /b`) do echo * %%i
endlocal
我想做的很简单:打印带有 *
前缀的当前目录的内容。像这样:
* .idlerc * .oracle_jre_usage * .swt * Searches * Contacts * Downloads * My Directory * Documents * Desktop * Favorites * Images * Saved Games * Music * 3D Objects
但是,当执行时,它说:
"usebackq" not expected at this time
我是 Batch 中的 for 语句的新手。有人可以帮忙吗?
最佳答案
使用FOR /F
并且您不需要在此处的选项中使用引号*,因为其中没有空格:
setlocal enableextensions
FOR /F usebackq %%i IN (`DIR /B`) DO ECHO * %%i
endlocal
*虽然保留引号不会造成任何伤害
关于windows - 批处理 : "usebackq" not expected at this time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41060170/