import os
import re
import shutil
def recurve_clear(root_dir: str, target: str):
dir_list = os.walk(root_dir)
for sub_root, sub_dirs, files in dir_list:
for sub_dir in sub_dirs:
if re.search(r'%s' % target, sub_dir):
path = "{}{}{}".format(sub_root, os.sep, sub_dir)
if os.path.exists(path):
shutil.rmtree(path)
print(path)
if __name__ == '__main__':
recurve_clear("F:\workspace-idea", '.idea')


