-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathpath.py
36 lines (32 loc) · 1.42 KB
/
path.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
import os
code_path = "Codes"
users = os.listdir(code_path)
base_path = os.path.abspath(
os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "."
)
for user in users:
# skip .DS_Store / .gitignore etc
if user.startswith("."):
continue
# for directories
for parent, directories, _ in os.walk(os.path.join(code_path, user)):
for directory in directories:
if " " in directory:
origin_path = os.path.join(parent, directory)
current_path = os.path.join(parent, directory.replace(" ", "-"))
origin_abs_path = os.path.join(base_path, origin_path)
current_abs_path = os.path.join(base_path, current_path)
print(origin_abs_path)
print(current_abs_path)
os.system("\\mv '%s' '%s'" % (origin_abs_path, current_abs_path))
# for files
for parent, _, files in os.walk(os.path.join(code_path, user)):
for file in files:
if " " in file:
origin_path = os.path.join(parent, file)
current_path = os.path.join(parent, file.replace(" ", "-"))
origin_abs_path = os.path.join(base_path, origin_path)
current_abs_path = os.path.join(base_path, current_path)
print(origin_abs_path)
print(current_abs_path)
os.system("\\mv '%s' '%s'" % (origin_abs_path, current_abs_path))