From: Alexander Schmidt Date: Fri, 16 Oct 2020 11:20:45 +0000 (+0200) Subject: do not look for alternative file in source dir X-Git-Url: http://git.treefish.org/~alex/photosort.git/commitdiff_plain/1847e0c3dd26952c7d4c2d19bac91fef43664d8e do not look for alternative file in source dir --- diff --git a/src/misc.py b/src/misc.py index 4cbbf74..7ef46f3 100644 --- a/src/misc.py +++ b/src/misc.py @@ -12,8 +12,10 @@ def walk_media_files(dir_path): def extract_timestamp(file_path): return os.path.getmtime(file_path) -def find_file(dir_path, file_name, file_size): +def find_file(dir_path, file_name, file_size, exclude_dir): for root, dirs, files in os.walk(dir_path): + if root == exclude_dir: + continue for f in files: if f == file_name: full_path = os.path.join(root, f) diff --git a/src/photosort.py b/src/photosort.py index 4c4149e..3124eae 100755 --- a/src/photosort.py +++ b/src/photosort.py @@ -33,7 +33,8 @@ for src_file_name, src_file_path in misc.walk_media_files(args.SOURCE_DIR): if not os.path.exists(dst_file_path): alt_dst_dir = misc.find_file(args.DEST_DIR, src_file_name, - os.path.getsize(src_file_path)) + os.path.getsize(src_file_path), + exclude_dir=args.SOURCE_DIR) if alt_dst_dir: dst_dir = alt_dst_dir dst_file_path = os.path.join(dst_dir, src_file_name)