Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively delete all folders starting with

I need to write a command in a .bat file that recursively deletes all the folders starting with a certain string. How may I achieve this ?

like image 338
glmxndr Avatar asked Nov 27 '09 08:11

glmxndr


People also ask

How can I delete all files in a directory recursively?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r .

What does rm {} do?

The rm command removes the entries for a specified file, group of files, or certain select files from a list within a directory. User confirmation, read permission, and write permission are not required before a file is removed when you use the rm command.

How do I delete all files from a certain name?

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

What is rm RF?

rm command in Linux is used to delete files. rm -r command deletes the folder recursively, even the empty folder. rm -f command removes 'Read only File' without asking. rm -rf / : Force deletion of everything in the root directory. rm -rf * : Force deletion of everything in the current directory/working directory.


1 Answers

This is the complete answer you are looking for:

FOR /D /R %%X IN (certain_string*) DO RD /S /Q "%%X"

where obviously you need to replace certain_string with the string your folders start with.

This deletes RECURSIVELY as you asked (I mean it goes throught all folders and subfolders).

like image 86
Marco Demaio Avatar answered Sep 21 '22 01:09

Marco Demaio