# from sign_script import delete_expire_file
# delete_expire_file(1)

import os

def get_folder_size(folder_path):
    total_size = 0
    for path, dirs, files in os.walk(folder_path):
        for f in files:
            fp = os.path.join(path, f)
            total_size += os.path.getsize(fp)
    return total_size





# 转换为更友好的单位
def convert_size(size_in_bytes):
    # 单位列表,从字节到千兆
    units = ['Bytes', 'KB', 'MB', 'GB', 'TB']

    # 获取单位索引
    unit_index = 0
    while size_in_bytes >= 1024 and unit_index < len(units) - 1:
        size_in_bytes /= 1024
        unit_index += 1

    # 格式化结果
    size_formatted = "{:.2f} {}".format(size_in_bytes, units[unit_index])
    return size_formatted

path = r'C:\Users\yys53\OneDrive'
files = os.listdir(path)
for file in files:
    folder_path = os.path.join(path, file)
    # print(len(str(folder_path)))
 
    size_in_bytes = get_folder_size(folder_path)
    folder_size = convert_size(size_in_bytes)

    # print(folder_path, '\n')
    
    # break
    if 'Bytes' not in str(folder_size) and 'KB' not in str(folder_size):
        print(folder_path, ":文件夹大小: " + folder_size, '\n\n')