Python.清理Visual Studio工程

"""
清理VS工程:
Visual Studio文件后缀['.DB', ],文件夹['DEBUG', 'RELEASE', 'X64', 'IPCH', ]

步骤:
1,选择目标文件夹路径。
2,遍历文件文件夹。
3,按目标要求处理。
"""

import shutil
import stat
from tkinter import messagebox
from tkinter.filedialog import *

if __name__ == '__main__':
    try:
        pass  # 1,选择目标文件夹路径
        strDirPath = askdirectory()
        if len(strDirPath):
            pass  # 2,遍历文件文件夹。3,按目标要求处理
            listExtension = ['.DB']
            listDir = ['DEBUG', 'RELEASE', 'X64', 'IPCH', 'OUT']
            for r, ds, fs in os.walk(strDirPath):
                for i in fs:
                    n, e = os.path.splitext(i)  # 前缀.后缀 -> (前缀,.后缀)
                    if e.upper() in listExtension:
                        os.chmod(os.path.join(r, i), stat.S_IWRITE)  # 剔除只读属性
                        os.remove(os.path.join(r, i))
                for i in ds:
                    if i.upper() in listDir:
                        shutil.rmtree(os.path.join(r, i))
            messagebox.showinfo('清理工程', '完成')
    except Exception as e:
        print(e)

猜你喜欢

转载自www.cnblogs.com/dailycode/p/12464660.html
今日推荐