-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextEditor.py
More file actions
63 lines (62 loc) · 1.72 KB
/
textEditor.py
File metadata and controls
63 lines (62 loc) · 1.72 KB
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
53
54
55
56
57
58
59
60
61
62
63
import sys
import os
import shutil
def leave():
sys.exit("You are leaving the Text Editor: Appen")
def read():
try:
filename = input("Enter the file name: ")
target = open(filename, "r")
readfile = target.read()
print(readfile)
except Exception as e:
print("There was a problem: %s" % (e))
def delete():
filename = input("Enter file name: ")
try:
os.unlink(filename)
except Exception as e:
print("There was a problem: %s" % (e))
def write():
try:
filename = input("Enter file name: ")
target = open(filename, "a")
while True:
append = input()
target.write(append)
target.write("\n")
if append.lower() == "menu":
break
except Exception as e:
print("There was a problem: %s" % (e))
def cwd():
try:
print(os.getcwd())
change = input("Change Y/N: ")
if change.startswith("y"):
path = input("New CWD: ")
os.chdir(path)
except Exception as e:
print("There was a problem: %s" % (e))
def rename():
try:
filename = input("Enter current file name: ")
new = input("Enter new file name: ")
shutil.move(filename, new)
except Exception as e:
print("There was a problem: %s" % (e))
while True:
print("Options: write, read, cwd, exit, delete, rename")
do = input("What would you like to do today: ")
if do.lower() == "write":
write()
elif do.lower() == "read":
read()
elif do.lower() == "delete":
delete()
elif do.lower() == "exit":
leave()
elif do.lower() == "cwd":
cwd()
elif do.lower() == "rename":
rename()