diff --git a/phototrie/batchrename.py b/phototrie/batchrename.py index 3f70d0e..605b78e 100644 --- a/phototrie/batchrename.py +++ b/phototrie/batchrename.py @@ -40,7 +40,7 @@ def cli(): pattern = re.compile(args.pattern) - for filename in sys.argv[3:]: + for filename in args.files: base = os.path.basename(filename) dirn = os.path.dirname(filename) new_base = pattern.sub(args.replacement, base) diff --git a/phototrie/datename.py b/phototrie/datename.py index cded8ed..140860b 100644 --- a/phototrie/datename.py +++ b/phototrie/datename.py @@ -20,9 +20,13 @@ def get_new_name(filename, date_matches): while True: if suffix == 0: - target = f"{dirn}/{year}-{month}-{date}_{hour}:{second}:{minute}{extension}" + target_base = f"{year}-{month}-{date}_{hour}:{second}:{minute}{extension}" else: - target = f"{dirn}/{year}-{month}-{date}_{hour}:{second}:{minute}_{suffix}{extension}" + target_base = ( + f"{year}-{month}-{date}_{hour}:{second}:{minute}_{suffix}{extension}" + ) + + target = os.path.join(dirn, target_base) if not os.path.exists(target): return target @@ -74,7 +78,9 @@ def cli(): found_raw = unextended + ".CR2" else: unextended_basename = os.path.basename(unextended) - try_next = os.path.dirname(filename) + "/CR2/" + unextended_basename + try_next = os.path.join( + os.path.dirname(filename), "CR2", unextended_basename + ".CR2" + ) if os.path.exists(try_next): found_raw = try_next diff --git a/phototrie/phototrie.py b/phototrie/phototrie.py index e8439c2..859b0f8 100644 --- a/phototrie/phototrie.py +++ b/phototrie/phototrie.py @@ -28,7 +28,7 @@ def prepare_processable(search_in: str): found_raw = unextended + ".CR2" else: unextended_basename = os.path.basename(unextended) - try_next = os.path.dirname(file) + "/CR2/" + unextended_basename + try_next = os.path.join(os.path.dirname(file), "CR2", unextended_basename + ".CR2") if os.path.exists(try_next): found_raw = try_next @@ -86,6 +86,9 @@ def cli(): print(" [file extension to process e.g. CR2 or jpg.") print("keybinds: B 'bad', 'G' good, 'P' pristine") + if len(sys.argv) < 2: + sys.exit(1) + to_process, tmp_dir = prepare_processable(".") dirs = "./bad", "./good", "./pristine"