# -*- coding: utf-8 -*- import os, sys, json RUN = r"F:\笔记本电脑盘\娱乐学习\水利智学系统\可运行版(解压即用,双击start.bat)" def size_of(p): total = 0 files = 0 for root, dirs, fs in os.walk(p, onerror=lambda e: None): for f in fs: try: total += os.path.getsize(os.path.join(root, f)) files += 1 except Exception: pass return total, files print("RUN exists:", os.path.exists(RUN)) rows = [] try: entries = list(os.scandir(RUN)) except Exception as e: print("scan err", e); sys.exit(1) for e in entries: if e.is_dir(follow_symlinks=False): s, n = size_of(e.path) rows.append((s, n, e.name + "/")) rows.sort(reverse=True) tot, totn = size_of(RUN) print("TOTAL %.2f GB files=%d" % (tot / 1073741824, totn)) print("-" * 60) for s, n, name in rows: print("%9.2f MB files=%6d %s" % (s / 1048576, n, name))