photoprism-fix/hardlink.py

30 lines
766 B
Python
Raw Permalink Normal View History

2024-11-05 22:17:32 +00:00
#!/usr/bin/env python3
"""
This module is intented to be a command line tool to recursively hardlink files. It should otherwise function in a similar way to cp -r.
"""
import argparse
import os
from pathlib import Path
def hardlink(src: Path, dst: Path):
if src.is_dir():
dst.mkdir(exist_ok=True)
for child in src.iterdir():
hardlink(child, dst / child.name)
else:
os.link(src, dst)
def main():
parser = argparse.ArgumentParser(description="Recursively hardlink files")
parser.add_argument("src", type=Path, help="source directory")
parser.add_argument("dst", type=Path, help="destination directory")
args = parser.parse_args()
hardlink(args.src, args.dst)
if __name__ == "__main__":
main()