Python Forum

Full Version: Small command shell
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there! Got code! Down here |
import os
print("mini command line v1.0.0")
print("type help for a list of commands.")
print("")

def commandline():
    commandline = input("C:\\system\\commands>")
    return commandline

commands = ["help", "dir", "exit"]

commandline_string = ""
while commandline_string != "exit":
    commandline_string = commandline()

    if not commandline_string in commands and commandline_string != "":
        print("Unable to run command. Please check that the command exists and that you have permission to use it.")

    if commandline_string == "help":
        print("These are the valid commands")
        for command in commands:
            print(command)

    elif commandline_string == "dir":
        files = os.listdir("/")
        for file in files:
            print(file)

    elif commandline_string == "dir /?":
        print("the dir command will display your computer directories.")

    elif commandline_string == "exit /?":
        print("the exit command will exit the XC command line command interpreter.")
That is the code for a mini command line. I did not know how to add files so...
If you mouse over the tool bar icons it's the blue and yellow one, when you hoover over it it says "insert python". Put your code between the tags please
Thanks for the help. I will do that next time.