前言
iOS项目一般将图片放到Image Assets中管理图片,迭代几个版本后,有些图片不一定能及时删除,这些图片会让项目的体积变大,所以需要定时清理。Android可以使用Lint完成这个任务,iOS可以使用Python脚本轻松做到。
一、安装工具The Silver Searcher
The Silver Searcher Git地址:https://github.com/ggreer/the_silver_searcher
使用命令安装,在终端输入命令:
brew install the_silver_searcher
二、Python脚本
执行脚本:
python cleanImage.py
脚本思路是这样的:
1、获取所有图片的路径和图片名字;
2、根据图片名字搜索工程中的代码,判断是否用到这个图片的名字。
3、如果图片没有在代码中使用,则删除。
全部脚本如下:
# coding=utf-8
import glob
import os
import re
import shutil
import time
path = '/Users/tianxiawoyougood/Git/SourceTree/hwmc/ios_hwmc_project/hwmc_ios_project/newhwmc'
ignore_dir_path = '/Users/ti