import os
import time
from datetime import datetime
def get_folder_size(folder_path):
total_size = 0
for root, dirs, files in os.walk(folder_path):
for file in files:
file_path = os.path.join(root, file)
total_size += os.path.getsize(file_path)
return total_size
def get_folder_file_count(folder_path):
file_count = 0
for root, dirs, files in os.walk(folder_path):
file_count += len(files)
return file_count
folder_path = "D:\\Git\\class_01"
polling_interval = 1 # 每秒检查一次
size_old = 0
file_old = 0
while True:
size = get_folder_size(folder_path)
size_kb = size / 1024 # 转换为KB
size_gb = size_kb / (1024*1024) # 转化为GB
file_count = get_folder_file_count(folder_path)
if size_old != size_kb or file_old != file_count:
print(f"文件夹大小: {size_kb:.2f} KB {size_gb:.2f} GB, 文件数量: {file_count}", datetime.now())
file_old = file_count
size_old = size_kb
time.sleep(polling_interval)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。