更新STM32CubeIDE及旧文件的清理

清理原因

  • 1、电脑每次更新完STM32CubeIDE后,都会残留上个版本的插件和一些替换掉的文件,而STM32CubeIDE是基于eclipse的,默认情况下不会清理这些文件。
  • 2、STM32CubeIDE更新后残留的旧文件会不断累积,我电脑的硬盘空间快不够用了。
  • 3、对照着时间一个个删去替换掉的文件是一个办法,但是遇到1000多项甚至更多文件,效率会很低。

解决方案

  • 使用python3,可以编写脚本解决上述问题。(声明:以下脚本是我测试时修改的,原作者是基于python2.x编写的。传送门:原作者python2脚本地址
# -*- coding: utf-8 -*-
import os
import re
from datetime import datetime

# directory="D:\\STM32CubeIDE\\STM32CubeIDE_1.0.2\\STM32CubeIDE\\features"
directory="D:\\STM32CubeIDE\\STM32CubeIDE_1.0.2\\STM32CubeIDE\\plugins"
dirBackup="D:\\STM32CubeIDE\\PluginsBackup"        #This folder is a kind of recycle bin for save deleted plugins. In case you have problems running eclipse after remove them you can restore them. If you don't detect any problem you can erase this folder to save disk space
manual=False    #Verifying deletion of each plugin manually (True) or automatic (False)

def globRegEx(directory,pat,absolutePath=True,type_=0):
    '''Function that given a directory and a regular pattern returns a list of files that meets the pattern

    :param str directory: Base path where we search for files that meet the pattern
    :param str pat: Regular expression that selected files must match
    :param bool absolutePath: Optional parameter that indicates if the returned list contains absolute (True) or relative paths (False)
    :param int type_: Type of selection 0: selects files and directories 1: only selects files 2: only selects directories
    :return: a list with the paths that meet the regular pattern
    '''
    names=os.listdir(directory)
    pat=re.compile(pat)
    res=[]

    for name in names:
        if pat.match(name)
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值