Skip to content

Instantly share code, notes, and snippets.

@EkriirkE
Created February 12, 2026 09:56
Show Gist options
  • Select an option

  • Save EkriirkE/9c425773227545512c3d480813cac286 to your computer and use it in GitHub Desktop.

Select an option

Save EkriirkE/9c425773227545512c3d480813cac286 to your computer and use it in GitHub Desktop.
Syncronise file timestamps between two locations
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