🐍 Python 3.10+

Get The NuGet packages cache Size Report (Python)

Recursively sums the size of the NuGet packages cache, read-only (no deletion).

By WindowsScripting.com · 682 B
nuget_cache_size_report.py
#!/usr/bin/env python3
"""
nuget_cache_size_report.py

Reports how much disk space the NuGet packages cache is using, read-only.

Usage:
    python nuget_cache_size_report.py
"""

import os
from pathlib import Path


def main() -> None:
    target = Path(os.path.expandvars(r'%USERPROFILE%\.nuget\packages'))
    if not target.exists():
        print(f"{target} does not exist on this machine.")
        return

    files = [f for f in target.rglob("*") if f.is_file()]
    total_bytes = sum(f.stat().st_size for f in files)

    print(target)
    print(f"  Files: {len(files)}")
    print(f"  Total size: {total_bytes / 1024 / 1024:.2f} MB")


if __name__ == "__main__":
    main()