user1816979
user1816979

Reputation: 531

dos command delete folder and files using a wild card character

In a DOS batch command window, I want to delete folders (and corresponding files within that directory) with part of the name that contains the following string (SUB

I want to start at a specfic root directory called C:\app2\proc.

I want to delete the directory and the files contained within the directory.

I want to delete folders where part of the file name is (SUB. What I have tried so far does not work.

Here is what I have tried to far:

del /f /s /q C:\app2\proc\*(SUB*

Note: the asterik before (SUB and the asterik after (SUB is not showing up in the display of what I have tried to far. Thus can you tell me how to solve this problem?

Upvotes: 1

Views: 7725

Answers (2)

Aaron
Aaron

Reputation: 57748

You can use a for loop to run through your files and send a variable (%x in this case) to rmdir with your path. Try this:

for /d %x in (*(sub*) do rmdir /s /q c:\app2\proc\%x

Upvotes: 1

Nick Andriopoulos
Nick Andriopoulos

Reputation: 10643

You porbably need to escape that ( character so that it does not get evaluated.

Checkout http://www.robvanderwoude.com/escapechars.php it seems you should replace ( with ^(

Upvotes: 0

Related Questions