Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a folder which name starts with something in command prompt (batch)

I read and tried some code from

  1. What's the fastest way to delete a large folder in Windows? (rmdir /s /q folder)

  2. Delete Files with Windows Command Prompt

I want to create a batch which delete a folder which name starts with Test_. I have a folder D:\Test_123_19_10_2012.

How to write in batch or command prompt ? Need regular expression ?

Thank you for patience.

like image 982
Snake Eyes Avatar asked Oct 19 '12 10:10

Snake Eyes


People also ask

How do I delete a file with a specific name?

From Explorer To delete matching files: enter *_bad. jpg in the search box, select the results and press Delete or Del.

How do I delete a folder that is not empty in cmd?

To remove a directory that is not empty, use the rm command with the -r option for recursive deletion. Be very careful with this command, because using the rm -r command will delete not only everything in the named directory, but also everything in its subdirectories.


1 Answers

Here you go

for /d %%a in (D:\Test_*) do rd %%a /q

The for loop is necessary as it seems rd doesn't support wildcards.

like image 85
Bali C Avatar answered Oct 08 '22 09:10

Bali C