Created
February 12, 2026 09:56
-
-
Save EkriirkE/9c425773227545512c3d480813cac286 to your computer and use it in GitHub Desktop.
Syncronise file timestamps between two locations
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
| import os | |
| import pathlib | |
| #For every file and folder found in "old", check if it exists in "new". If it does, update the "new" timestamp to the "old" couterpart. | |
| old="/home/erik/Development.new/" | |
| new="/home/erik/Development/" | |
| i=e=0 | |
| for f in pathlib.Path(old).rglob("*"): | |
| lf=os.path.join(new,f.as_posix()[len(old):]) | |
| if f.is_dir(): continue | |
| if os.path.exists(lf): | |
| os.utime(lf,(f.stat().st_mtime,f.stat().st_mtime)) | |
| print(".",end="",flush=True) | |
| else: | |
| #print("\nfile missing",lf) | |
| print("x",end="",flush=True) | |
| e+=1 | |
| i+=1 | |
| print(f"\n{i} items processed. {e} missing.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment