Created
January 7, 2025 15:34
-
-
Save jericjan/0be2284bb1b766bd4cf5d106c6696f6d to your computer and use it in GitHub Desktop.
transferring date modified data to another folder (python)
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
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)) | |
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
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