-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem4.py
More file actions
45 lines (34 loc) · 1004 Bytes
/
Copy pathProblem4.py
File metadata and controls
45 lines (34 loc) · 1004 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
"""
Created on Fri May 14 19:11:02 2021
@author: amit.pochinapeddi
"""
path = input("Enter the path you want to use")
inputdata = input("Enter the cd path absolute or relative")
print(path)
print(inputdata)
def cd(data,path):
alphabet = None
data = data.split("/")
for i in range(len(data)):
if data[i] not in path and data[i]!="..":
alphabet = data[i-1]
break
if alphabet is None:
pathindex = path.index(data[-1])
return path[:pathindex+1]
else:
try:
beforeindex = path.index(alphabet)
afterindex = inputdata.index(alphabet)
except Exception:
path = path[:-1]
data = data[-1]
path+=data
return path
beforepath=""
beforepath+=path[:beforeindex]
beforepath+=inputdata[afterindex:]
return beforepath
result = cd(inputdata,path)
print("The path is changed to ",result)