24 11 2021
import os
import shutil
from os.path import join, getsize


def check_video_folder(file_path, limit=500, days=31):
    '''

    @param file_path: 录屏文件夹路径
    @param limit: 录屏文件大小限制 单位GB
    @param days: 录屏文件保留天数
    @return:
    '''

    while 1:
        size = 0
        for root, dirs, files in os.walk(file_path):
            size += sum([getsize(join(root, name)) for name in files])
        gsize = size / 1024 / 1024 / 1024
        print('当前文件夹大小:{:.2f}GB,限制大小:{}GB'.format(gsize,limit))
        if gsize > limit:
            for file_dir in os.listdir(file_path):
                print('文件夹占用空间超限,删除:', file_dir)
                shutil.rmtree(os.path.join(file_path, file_dir))
                break
        else:
            break
    print('文件夹占用检查完毕')


if __name__ == '__main__':
    check_video_folder(r'example')

 

延伸阅读
    < /body> < /html>