Created
September 2, 2019 14:02
-
-
Save lvm/3320b755c7b0b07a2958583b218a0729 to your computer and use it in GitHub Desktop.
find dupe directories, only 1 level.
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
#!/usr/bin/env python3 | |
import argparse | |
from pathlib import Path | |
def get_dirs(path): | |
return dict([(x.name,x.as_posix()) | |
for x in path.iterdir() | |
if x.is_dir()]) | |
def if_in(x, y): | |
return [d for d in list(x.keys()) if d in list(y.keys())] | |
def find_dupes(dir_a, dir_b, in_a): | |
dir_a = get_dirs(Path(args.dir_a)) | |
dir_b = get_dirs(Path(args.dir_b)) | |
dupes = sorted(if_in(dir_b, dir_a) if in_a else if_in(dir_a, dir_b)) | |
return (list(map(lambda d: (dir_a.get(d), dir_b.get(d)), dupes))) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("dir_a") | |
parser.add_argument("dir_b") | |
parser.add_argument('-a', action="store_true", default=False) | |
parser.add_argument('-b', action="store_true", default=False) | |
args = parser.parse_args() | |
if args.dir_a and args.dir_b: | |
for dupe in find_dupes (args.dir_a, args.dir_b, args.a and not args.b): | |
print (dupe) | |
else: | |
parser.print_help() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment