import os,sys,shutil
def search(rootdir,search_dir_name):
if os.path.isdir(rootdir):
list_new = os.listdir(rootdir)
for it in list_new:
if it == search_dir_name:
#os.rmdir(os.path.join(rootdir,it)) #不能删除有文件的文件夹
shutil.rmtree(os.path.join(rootdir,it))
else:
search(os.path.join(rootdir,it),search_dir_name)
else:
return
search("E:\\code\\trunc\\src\\video\\","Debug")
search("E:\\code\\trunc\\src\\video\\","Release")
python 查找指定名称的目录并删除
最新推荐文章于 2024-08-22 11:02:57 发布
本文介绍了一个使用Python编写的脚本,该脚本能够递归地搜索指定根目录下的所有子目录,并批量删除名为'Debug'和'Release'的目录。通过递归遍历文件树,此脚本可以轻松地清理开发环境中不再需要的调试和发布版本目录。
983

被折叠的 条评论
为什么被折叠?



