Add move_all.py.
This commit is contained in:
parent
9ad4dc37e5
commit
3eb72adfda
1 changed files with 29 additions and 0 deletions
29
move_all.py
Normal file
29
move_all.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue