Python脚本清理Winform项目下的临时文件及目录

import os
import os.path
import shutil
import sys

rootdir = sys.path[0]

for parent, dirnames, filenames in os.walk(rootdir):
    for dirname in dirnames:
        pathName = os.path.join(parent, dirname)
        print(pathName)
        if(pathName.endswith('bin') or pathName.endswith('obj')
           or "\OutPutPath\logs" in pathName or "\OutPutPath\Data" in pathName):
            shutil.rmtree(pathName)

    for filename in filenames:
        fileName = os.path.join(parent, filename)
        if(fileName.endswith(".suo") or fileName.endswith(".pdb") or "\OutPut\BackupPath" in fileName
           or "\OutPutPath\Export" in fileName or "\OutPutPath\ExportLog" in fileName
           or ".vshost." in fileName):
            os.remove(fileName)

猜你喜欢

转载自blog.csdn.net/henreash/article/details/79177041