简体   繁体   中英

Dir is removed via command in cmd but not with same command in bat file

I am trying to remove a directory, that match some prefix.

I wish that it be possible by invoking some bat file.

Writing for /D %f in (C:\\Windows\\Temp\\_MEI*) do rmdir /s %f directly to cmd does delete every folder that match the prefix.

Though, invoking test.bat that only has the command line above simply does nothing and i get "... was unexpected at this time" error.

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>

Why is that?

See the 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 .

Or run for /? at the command prompt.

Basically, use %%f instead of %f .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM