HOW THE SCRIPT WORKS

1. Read each regular file in the current directory (Path.iterdir()).
2. ASCII conversion – either transliterate (default) or strip non‑ASCII (--remove).
3. Windows sanitisation – removes illegal characters, control codes, trailing spaces/periods, and protects reserved device names.
4. Linux ext4 sanitisation – removes / and NUL, optionally strips a leading dot (--keep-dot disables this), and truncates the name to ≤ 255 bytes (the ext4 limit).
The truncation is UTF‑8‑aware, so multibyte characters aren’t split mid‑byte.
5. Re‑assemble the sanitized stem with the original file extension.
6. Rename safely, skipping any operation that would overwrite an existing file and reporting conflicts.

RUNNING THE SCRIPT

# Non‑recursive (default) – only files in the current folder
python rename_crossplatform_safe.py

# Recursive, showing what would happen without changing anything
python rename_crossplatform_safe.py -r --dry-run

# Recursive, removing non‑ASCII characters and keeping leading dots
python rename_crossplatform_safe.py -r --remove --keep-dot

Typical output:

Scanning directory: /home/user/projects
Renamed: Café‑résumé — ☕️.txt → Cafe-resume-.txt
Renamed: CON.log → CON_.log
Renamed: .secret.cfg → secret.cfg
✅ Done.