import os import shutil del_list = [] def del_svn(f): fs = os.listdir(f) for f1 in fs: tmp_path = os.path.join(f, f1) if not os.path.isdir(tmp_path): # print('文件: %s' % tmp_path) pass else: if '.svn' in tmp_path: del_list.append(tmp_path) else: del_svn(tmp_path) if __name__ == '__main__': del_svn(os.getcwd() + '\\dist') count_size = 0 for item in del_list: for fpathe, dirs, fs in os.walk(item): for f in fs: count_size += os.path.getsize(os.path.join(fpathe, f)) shutil.rmtree(item) print('执行完毕,共删除 %s 个目录, %s MB' % (len(del_list), round((count_size / 1024 / 1024), 2)))