#!/usr/bin/env python3
"""
list_file_sizes.py
------------------
Scans the current directory (non-recursive) and writes a CSV:

Filename, File Size

Where "File Size" is in bytes.

Usage:
  python3 list_file_sizes.py
  # or choose a custom output file:
  python3 list_file_sizes.py --output sizes.csv
"""

import argparse
import csv
from pathlib import Path

def main():
    ap = argparse.ArgumentParser(description="List file sizes (bytes) for all files in the current directory.")
    ap.add_argument("--output", default="file_sizes.csv", help="Output CSV filename (default: file_sizes.csv)")
    args = ap.parse_args()

    here = Path(".").resolve()
    files = sorted([p for p in here.iterdir() if p.is_file() and p.name != args.output])

    out_path = here / args.output
    with out_path.open("w", encoding="utf-8", newline="") as f:
        w = csv.writer(f)
        w.writerow(["Filename", "File Size"])
        for p in files:
            try:
                size = p.stat().st_size  # bytes
            except Exception:
                size = ""
            w.writerow([p.name, size])

    print(f"[ok] wrote {out_path} ({len(files)} files)")

if __name__ == "__main__":
    main()
