-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfname2.py
More file actions
49 lines (43 loc) · 1.35 KB
/
Copy pathfname2.py
File metadata and controls
49 lines (43 loc) · 1.35 KB
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
44
45
46
47
48
49
# ------------------------------------------------------------------------------
# Python Scripts scriptarium/[fname2.py]
# (c) balarabe@protonmail.com
# ------------------------------------------------------------------------------
import os
os.chdir('T:\\eBooks') # <- only uncomment for debugging
sources = {}
with open("list1.txt", mode='r', encoding='ansi') as fl:
lines = fl.read().split('\n')
for ln in lines:
if len(ln) < 34:
continue
id = ln[:32]
s = ln[33:]
sources[id] = s
with open("list2.txt", mode='r', encoding='ansi') as fl:
lines = fl.read().split('\n')
for ln in lines:
if len(ln) < 34:
continue
ln = ln.strip()
id = ln[:32].strip()
new_name = ln[33:].strip()
#
if not id in sources:
print("NO MATCH:", id, new_name)
continue
#
path = sources[id]
old_name = path
j = path.rfind('\\')
if j > -1:
old_name = path[j+1:]
#
if new_name == old_name:
continue
#
try:
os.rename(path, new_name)
print(path, "--->", new_name)
except WindowsError:
print("FAILED:", path, "--->", new_name)
# end