Python遍历清理VC项目中的Debug Release ipch 及 sdf

VC编译后生成的Debug、Release、ipch目录及sdf文件占用大量空间,不方便代码保存,写了个Python程序自动遍历清理。

import os
import shutil
  
def remove_vc_extra(root_dir):
    list_dirs = os.walk(root_dir, topdown=False)
    for dirpath, dirnames, filenames in list_dirs:
        for dirname in dirnames:
            if dirname == 'Debug' or dirname == 'Release' or dirname == 'ipch':
                shutil.rmtree(os.path.join(dirpath, dirname), ignore_errors=True)
        for filename in filenames:
            path, ext = os.path.splitext(filename)
            if ext == '.sdf':
                os.remove(os.path.join(dirpath, filename))
              
if __name__ == '__main__':
    root_dir = input('根目录:')
    remove_vc_extra(root_dir)

发表评论

电子邮件地址不会被公开。