-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalize.py
More file actions
25 lines (22 loc) · 910 Bytes
/
normalize.py
File metadata and controls
25 lines (22 loc) · 910 Bytes
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
import sys
def normalize(string, normalized=''):
def read_tail(string, normalized):
if string[0] == '/':
return normalize(string[1:], normalized + string[0])
elif string[0] == '.':
while string[0] == '.':
string = string[1:]
return normalize(string[1:], normalized)
else:
return normalize(string, normalized)
if string == '':
return normalized
else:
if string[0] == '/':
return read_tail(string[1:], normalized + string[0])
else:
return normalize(string[1:], normalized + string[0])
if len(sys.argv)<2:
print("You did not enter an directory to parse. \nIn order to use this normalizer, please enter at least one directory.\nWith multiple directories, separate the directories with a space.")
for arg in sys.argv[1:]:
print(normalize(arg))