-
Notifications
You must be signed in to change notification settings - Fork 0
/
copyfiles.py
43 lines (34 loc) · 997 Bytes
/
copyfiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# python 3
from __future__ import print_function
import os
import sys
from shutil import copyfile
# TODO improve arg parsing (use a library)
renames = sys.argv[1].strip()
force = False
if len(sys.argv) > 2:
force = sys.argv[2].strip() == '-f'
if force:
print("-f detected: will overwrite files")
with open(renames, "r") as f:
while True:
x = f.readline()
# TODO allow for empty lines in the input file -- only stop at end of file
if x is None or x.strip() == '': break
args = x.split(',')
a = args[0].strip()
b = args[1].strip()
print(a, end = " ")
print(" --> ", end = " ")
print(b)
try:
copyfile(a, b)
except FileNotFoundError as e:
print(e)
except FileExistsError as e:
if force:
print("Overwriting {}".format(b))
os.remove(b)
copyfile(a, b)
else:
print(e)