0
我正在構建希望是MS-DOS樣式的操作系統,但是我遇到了有關文件夾的困難。無論何時我嘗試創建或更改目錄,我都會收到一條消息將輸入字符串與某些選項進行比較時出現意外輸出
「未找到命令」。
我不知道爲什麼會發生這種情況,我真的可以使用一些幫助。下面是我得到了什麼:
import os
def cmdLvl2():
print("Use the 'leave' command to shut down the system. Use the 'type' command to start a text editor. You can also type 'clear' to clear the screen. Type 'help -a' for more options.")
tcmdLvl2 = input("~$: ")
if tcmdLvl2 == ("leave"):
quit()
if tcmdLvl2 == ("type"):
typer()
if tcmdLvl2 == ("clear"):
os.system('cls')
if tcmdLvl2 == (""):
dcmdLvl2()
if tcmdLvl2 == ("help -a"):
print("You can use the command 'md' to make a new directory. Use the cd command to access this directory. Additionally, use 'list' to show all sub-folders in your current directory.")
cmdLvl2()
if tcmdLvl2 == ("md"):
directoryName = input("Name of directory: ")
os.mkdir(directoryName)
if not os.path.exists(directoryName):
os.mkdir(directoryName)
dcmdLvl2()
if tcmdLvl2 == ("cd"):
changedDIR = input("Directory name: ")
os.chdir(changedDIR)
if not os.path.exists(changedDIR):
print("Directory not found.")
dcmdLvl2()
if tcmdLvl2 == "list":
os.system('dir')
if tcmdLvl2 != ("leave", "type", "clear", "", "help -a", "cr", "cd", "list"):
print("Command not found.")
dcmdLvl2()
def dcmdLvl2():
tcmdLvl2 = input("~$: ")
if tcmdLvl2 == ("leave"):
quit()
if tcmdLvl2 == ("type"):
typer()
if tcmdLvl2 == ("clear"):
os.system('cls')
if tcmdLvl2 == (""):
dcmdLvl2()
if tcmdLvl2 == ("help"):
cmdLvl2()
if tcmdLvl2 == ("cr"):
directoryName = input("Name of directory: ")
os.mkdir(directoryName)
if not os.path.exists(directoryName):
os.mkdir(directoryName)
dcmdLvl2()
if tcmdLvl2 == ("cd"):
changedDIR = input("Directory name: ")
os.chdir(changedDIR)
if not os.path.exists(changedDIR):
print("Directory not found.")
dcmdLvl2()
if tcmdLvl2 == ("list"):
os.system('dir')
if tcmdLvl2 != ("leave", "type", "clear", "", "help", "help -a", "cr", "cd", "list"):
print("Command not found.")
dcmdLvl2()
def typer():
print("Start typing to get started. Unfortunately, you cannot currently save your files.")
typerCMD = input(" ")
dcmdLvl2()
def CMDLine():
print("Hello, and welcome to your new operating system. Type 'help' to get started.")
cmd = input("~$: ")
if cmd == ("help"):
cmdLvl2()
if cmd == ("leave"):
quit()
if cmd == ("type"):
typer()
if cmd == ("clear"):
os.system('cls')
if cmd == (""):
dcmdLvl2()
if cmd == ("help -a"):
print("You can use the command 'cr' to make a new directory. Use the sd command to access this directory. Additionally, use 'list' to show all sub-folders in your current directory.")
cmdLvl2()
if cmd != ("leave", "type", "clear", "", "help -a"):
print("Command not found.")
dcmdLvl2()
def redirect():
signIn()
def mUserRedirect():
makeUser()
def PwordSignIn():
rPword = input("Password: ")
with open('passwords.txt', 'r') as f:
for line in f:
if rPword == (line):
CMDLine()
else:
print("Incorrect password.")
signIn()
def signIn():
rUname = input("Username: ")
with open('usernames.txt', 'r') as f:
for line in f:
if rUname == (line):
PwordSignIn()
else:
print("Username not found.")
mUserRedirect()
def makeUser():
nUname = input("New username: ")
nPword = input("Create a password for the user: ")
with open('usernames.txt', 'w') as f:
f.write(nUname)
with open('passwords.txt', 'w') as f:
f.write(nPword)
signIn()
print("Create a new user? Warning: This will delete any other users. (Y/N) ")
nUser = input("")
if nUser == ("N"):
signIn()
if nUser == ("n"):
signIn()
if nUser == ("Y"):
makeUser()
if nUser == ("y"):
makeUser()
而且,如果有人能幫助我與我的文件夾的設置,我希望它只是程序而不是我的基地,Windows操作系統中創建的文件夾。我怎麼能這樣做?