使用Windows批处理脚本递归删除文件夹 [英] deleting folders recursively using windows batch script
问题描述
我有一个文件夹,该文件夹下有多个子文件夹.我想删除子文件夹/示例下的所有测试文件夹.如何使用Windows批处理脚本执行此操作?请注意,其中没有测试文件夹.
I have a folder with multiple subfolders under it. I would like to delete all test folders under the subfolders/example. How can I do this using windows batch script? Note that there is no test folder in some.
我知道如何删除mainfolder/subfolder1/example/test.但是在每个子文件夹下都需要递归删除,即删除mainfolder/*/example/test.
I know how to delete mainfolder/subfolder1/example/test. But am stuck with recursively deleting under each subfolder i.e delete mainfolder/*/example/test.
TIA
例如:
mainfolder
subfolder1
source
example
test
subfolder2
source
example
test
subfolderX
source
example
推荐答案
for /r "c:\sourcedir" /d %a in (*) do if /i "%~nxa"=="test" echo rd /s /q "%a"
直接在提示符下输入
-将每个%
都加倍以用作批处理行.
direct from the prompt - double each %
to use as a batch line.
适当地替换 c:\ sourcedir
必需的 rd
只是 echo
来显示他的脚本打算做什么.经过测试以实际执行删除操作后,删除 echo
关键字.
required rd
is merely echo
ed to show what he script intends to do. Remove the echo
keyword after testing to actually perform the deletion.
这篇关于使用Windows批处理脚本递归删除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!