Created
February 12, 2026 00:19
-
-
Save f2koi-shiftup/3f017e1cbb1774f4155723ab7edc792e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pathlib import Path | |
| ROOT = Path(r"a/b/c/d") | |
| BOM_UTF8 = b"\xEF\xBB\xBF" | |
| def strip_utf8_bom(path: Path) -> bool: | |
| data = path.read_bytes() | |
| if not data.startswith(BOM_UTF8): | |
| return False | |
| path.write_bytes(data[len(BOM_UTF8):]) | |
| return True | |
| def strip_bom_in_tree(root: Path) -> tuple[int, int]: | |
| if not root.exists(): | |
| raise FileNotFoundError(root) | |
| total = 0 | |
| modified = 0 | |
| for cs_file in root.rglob("*.cs"): | |
| if not cs_file.is_file(): | |
| continue | |
| total += 1 | |
| try: | |
| if strip_utf8_bom(cs_file): | |
| modified += 1 | |
| except OSError: | |
| pass | |
| return total, modified | |
| if __name__ == "__main__": | |
| total, modified = strip_bom_in_tree(ROOT) | |
| print(f"Scanned: {total} Modified: {modified}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment