From 3eb72adfda08cffa052a53fae4abf127e15d7d85 Mon Sep 17 00:00:00 2001 From: Ethan Dalool <git@voussoir.net> Date: Tue, 8 Sep 2020 22:02:28 -0700 Subject: [PATCH] Add move_all.py. --- move_all.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 move_all.py diff --git a/move_all.py b/move_all.py new file mode 100644 index 0000000..97bd66f --- /dev/null +++ b/move_all.py @@ -0,0 +1,29 @@ +''' +Move all of the files into the destination directory, aborting the operation if +even a single file collides with a file in the destination. +''' +import sys +import shutil + +from voussoirkit import pathclass +from voussoirkit import winglob + +argv = sys.argv[1:] + +if len(argv) < 2: + raise TypeError() + +patterns = argv[:-1] +files = [file for pattern in patterns for file in winglob.glob(pattern)] +files = [pathclass.Path(file) for file in files] +destination = pathclass.Path(sys.argv[-1]) +if not destination.is_dir: + raise TypeError(destination) + +if any(destination.with_child(file.basename).exists for file in files): + raise Exception(file.basename) + +for file in files: + new_path = destination.with_child(file.basename) + print(new_path.absolute_path) + shutil.move(file.absolute_path, new_path.absolute_path)