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 ?
To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r .
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.
From Explorer To delete matching files: enter *_bad. jpg in the search box, select the results and press Delete or Del.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With