Skip to content

Instantly share code, notes, and snippets.

@jericjan
Created January 7, 2025 15:34
Show Gist options
  • Save jericjan/0be2284bb1b766bd4cf5d106c6696f6d to your computer and use it in GitHub Desktop.
Save jericjan/0be2284bb1b766bd4cf5d106c6696f6d to your computer and use it in GitHub Desktop.
transferring date modified data to another folder (python)
from pathlib import Path
import os, json
curr_folder = Path.cwd()
with open("mod_dates.json", encoding="utf-8") as f:
data = json.load(f)
for old, mtime in data.items():
new = curr_folder / old
if new.exists():
print(f"{new.name} -- {new.stat().st_mtime_ns} to {mtime}")
os.utime(new, ns=(new.stat().st_atime_ns, mtime))
from pathlib import Path
import json
data = {}
curr_folder = Path.cwd()
for file in curr_folder.rglob("*"):
# This includes folders, which apparently have their own date modified data
data[str(file.relative_to(curr_folder))] = file.stat().st_mtime_ns
print(file.name)
with open("mod_dates.json", "w", encoding="utf-8") as f:
f.write(json.dumps(data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment