-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos.py
52 lines (45 loc) · 1 KB
/
os.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
running = True
os.chdir("sys")
# const
root = os.getcwd()
# commands
def pwd(silent = False):
dir = os.getcwd().replace(root, "")
if dir == "":
if silent == False:
print("/")
return "/"
else:
if silent == False:
print(dir)
return dir
def cd(inp):
try:
out = inp.replace("cd ", "")
except:
out = inp.replace("cd", "")
if out.startswith("/"):
try:
os.chdir(root + out)
except:
print("directory does not exist")
else:
try:
os.chdir(out)
except:
print("directory does not exist")
dir = os.getcwd()
if not dir.startswith(root):
os.chdir(root)
# main loop
while running:
inp = input(pwd(True) + " $ ")
if inp.startswith("cd"):
cd(inp)
elif inp == "pwd":
pwd()
elif inp == "exit":
running = False
else:
print("command does not exist")