23 lines
754 B
Python
23 lines
754 B
Python
from pathlib import Path
|
|
import shutil
|
|
|
|
def merge_into(src: Path | str, dest: Path | str, check_date: bool = True):
|
|
src = Path(src)
|
|
dest = Path(dest)
|
|
|
|
changed = False
|
|
|
|
for (cd, _, files) in src.walk():
|
|
for file in files:
|
|
src_file = cd / file
|
|
dest_file = dest / src_file.relative_to(src)
|
|
|
|
# Don't update if dest is newer than source
|
|
if check_date and dest_file.exists() and src_file.stat().st_mtime < dest_file.stat().st_mtime:
|
|
continue
|
|
|
|
dest_file.parent.mkdir(parents=True, exist_ok=True)
|
|
_ = shutil.copyfile(src_file, dest_file)
|
|
changed = True
|
|
|
|
return changed |