first attempt for fix_dir_mtime.py, plus some minor changes
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
# Python
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
.pytest_cache/
|
||||
|
||||
# Editors / OS
|
||||
.DS_Store
|
||||
|
||||
# Optional: local scratch
|
||||
*.tmp
|
||||
*.swp
|
||||
Executable
+34
@@ -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)
|
||||
Reference in New Issue
Block a user