清理Xcode

每次清理Xcode都要去删除好几个目录,感觉有点麻烦,简单写了一个python脚本.

#!/usr/bin/python
# -*- coding: utf-8 -*-
#coding=utf-8
import os
import shutil

#mac用户名
user = 'xxx'
#前缀文件名
prefix = r'/Users/' + user
#指定删除目录的集合(https://www.jianshu.com/p/225a4b3dd88e)
paths = [
    r'/Desktop/zzzzzz',
    r'/Library/Developer/Xcode/DerivedData',
    r'/Library/Developer/Xcode/iOS DeviceSupport',
    r'/Library/Developer/Xcode/Archives',
    r'/Library/Developer/Xcode/Products',
    r'/Library/Developer/CoreSimulator/Devices',
    r'/Library/Developer/XCPGDevices'
]
path = r'/Users/droog/Desktop/zzzzzz'

def del_file(path):
    
#   read all the files under the folder
    fileNames = os.listdir(path)
    for fileName in fileNames:
        c_path = os.path.join(path, fileName)
        if os.path.isdir(c_path):
#           del_file(c_path)
            shutil.rmtree(c_path)
            print('delete folder: ' + c_path)
        else:
            os.remove(c_path)
            print('delete file: ' + c_path)

if __name__ == '__main__':
    for path in paths:
        del_file(prefix + path)

保存脚本内容 修改user为mac的用户名称,在终端运行脚本.

你可能感兴趣的:(清理Xcode)