gpt4 book ai didi

windows - 通过 cmd 中的命令删除目录,但在 bat 文件中不使用相同的命令

转载 作者:可可西里 更新时间:2023-11-01 11:23:19 29 4
gpt4 key购买 nike

我正在尝试删除一个与某些前缀匹配的目录。

我希望通过调用一些 bat 文件成为可能。

for/D %f in (C:\Windows\Temp\_MEI*) do rmdir/s %f 直接写入 cmd 会删除与前缀匹配的每个文件夹。

不过,调用只有上面的命令行的 test.bat 什么都不做,我得到“......此时是意外的”错误。

C:\Users\Borat\olympus-skeleton\dist>test.bat
\Windows\Temp\_MEI*) was unexpected at this time.
C:\Users\Borat\olympus-skeleton\dist>for /D \Windows\Temp\_MEI*) do rmdir /s f
C:\Users\Borat\olympus-skeleton\dist>

这是为什么?

最佳答案

参见 documentation for for :

Syntax

for {%%|%}<Variable> in (<Set>) do <Command> [<CommandLineOptions>]

Parameters

Parameter        Description

{%%|%}<Variable>    Required. Represents a replaceable parameter. Use a single percent sign (%) to carry out the for command at the command prompt. Use double percent signs (%%) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %A, %B, or %C.

或者运行for /?在命令提示符下。

基本上,使用 %%f而不是 %f .

关于windows - 通过 cmd 中的命令删除目录,但在 bat 文件中不使用相同的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54850351/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com