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
| #!/usr/bin/env python3
import os
# Linux and Mac examples.
def custom(path):
i = path.find('/.')
newPath = ''
while(i >= 0):
j = path.find('./', i)
if j < i:
break
newPath += path[:i] + "/" + "../"*(j - i)
path = path[j+2:]
i = path.find('/.')
if newPath:
newPath += path
return newPath
else:
return onePath
for onePath in [ '/Users/login/Documents',
'/Users/login/Documents/./Music',
'/Users/login/Documents/../Documents/Misc',
'/Users/login/Documents/.../Documents/Misc',
'/Users/login/Documents/..../Documents/Misc/../Test'
]:
pathCustomized = custom(onePath)
print( '',
onePath,
pathCustomized,
os.path.normpath(pathCustomized),
sep = '\n') |