batch-file - 批处理文件for循环不喜欢括号

标签 batch-file cmd

我正在编写一个简单的批处理文件,它将为目录中的每个文件夹执行一组命令。这是我的代码:

for /D %%x in ("C:"*) do echo "Folder found!">>test.txt

这有效。问题是,当我添加括号在每个文件夹中执行多个命令时,操作会崩溃。它不运行循环:

for /D %%x in ("C:"*) do(
   echo "Folder found!">>test.txt
)

导致崩溃。

我在谷歌上找不到任何东西。有人有什么想法吗?

最佳答案

这只是 do 更改为 do (

此外,模式 "C:"* 是前面带有 "C:" 的当前目录,对于 C:\ 本身;

for /D %%x in ("C:\*") do (
    echo "Folder found!" 
)

关于batch-file - 批处理文件for循环不喜欢括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23933283/

相关文章:

java - Java JAR错误CMD找不到或加载主类jar-

javascript - 如何在 node.js 中执行 hello world javascript 文件

java - 我可以将 Java 运行时环境复制到其他计算机吗?

windows - 为什么特定的 Windows 批处理参数会导致崩溃?

windows - 使用xcopy复制所有desktop.ini

internet-explorer - 如何从命令提示符设置 Internet Explorer 安全设置

command-line - 批处理文件 : copy all file except those its name contain some substring

windows - 将 .txt 上传到 FTP 的批处理文件

mysql - 批处理脚本返回 % 符号

if-statement - 批量处理多个 If