first attempt for fix_dir_mtime.py, plus some minor changes

This commit is contained in:
2026-02-25 10:12:24 +01:00
parent a0a5b3321c
commit 9a7d05ba77
3 changed files with 47 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
# Python
__pycache__/
*.pyc
*.pyo
*.pyd
.pytest_cache/
# Editors / OS
.DS_Store
# Optional: local scratch
*.tmp
*.swp
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
import os
import sys
from pathlib import Path
def update_dir_mtime(path: Path):
if not path.is_dir():
return path.stat().st_mtime
newest = 0
for child in path.iterdir():
if child.is_dir():
child_mtime = update_dir_mtime(child)
else:
child_mtime = child.stat().st_mtime
newest = max(newest, child_mtime)
if newest > 0:
os.utime(path, (newest, newest))
return max(newest, path.stat().st_mtime)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: fix_dir_mtime.py <directory>")
sys.exit(1)
root = Path(sys.argv[1]).resolve()
update_dir_mtime(root)