From 6425a3f20b714e56859aca880e1563e213cec029 Mon Sep 17 00:00:00 2001 From: max Date: Wed, 3 Jul 2024 14:35:50 +1000 Subject: [PATCH] add cd functionality --- main.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/main.py b/main.py index 5cab815..524d84f 100755 --- a/main.py +++ b/main.py @@ -19,6 +19,27 @@ try: print(currentDirectory) if command == "exit": exit() + if command == "cd": + try: + cdDirectory = input("Directory: ") + if cdDirectory[0] == "/": + if os.path.isdir(cdDirectory) == False: + if os.path.isfile(cdDirectory) == True: + print("That's not a directory, that's a file!") + else: + print("That directory doesn't exist.") + else: + currentDirectory = cdDirectory + else: + if os.path.isdir(currentDirectory + cdDirectory) == False: + if os.path.isfile(currentDirectory + cdDirectory) == True: + print("That's not a directory, that's a file!") + else: + print("That directory doesn't exist.") + else: + currentDirectory = cdDirectory + except Exception: + print("Either there was an error or that file doesn't exist.") elif command == ("cat"): try: catFile = input("File to catalog: ")