def remove(times): # Debug message if it is enabled if(systemvariables.read("debugMsg") == 1): print(systemvariables.color.YELLOW + systemvariables.color.BOLD + "[Debug]" + systemvariables.color.END + " Pushd: " + str(systemvariables.directorystack)) # Counter j = 0 # Loop to do this as many times as requested while(j != times): # Another Counter i = 0 # Do this for all items in the stack while(i < 7): #print(systemvariables.directorystack) # Move the item we are looking at to the right systemvariables.directorystack[i] = systemvariables.directorystack[i+1] # Increment i += 1 # Delete the last item systemvariables.directorystack[7] = "" # Increment the counter to prepare to do it again! j += 1 # Debug message if(systemvariables.read("debugMsg") == 1): print(systemvariables.color.YELLOW + systemvariables.color.BOLD + "[Debug]" + systemvariables.color.END + " Pushd: " + str(systemvariables.directorystack))
def baseusrfilerepair(): # We need to be in this directory, stored as a System Variable we # set at Startup os.chdir(systemvariables.read("settingspath")) # If needed, create a new user account if ((os.path.exists("Settings/ivhzadgz.bws") == False) or (os.path.exists("Settings/kvnnadgz.bws") == False)): username.get() print("Solving Problems...") # Get the username information usrnam = open("Settings/ivhzadgz.bws") # Put the contents of the username in a variable so we can use # it any time without having to be in that directory usrname = usrnam.read() # We don't need the origonal variable anymore usrnam.close() # Start Recreating Folders os.chdir("../Users") os.mkdir(usrname + "/") os.chdir(usrname) os.mkdir("Documents") os.mkdir("Downloads") # Success message and go to the correct directory print("Repair has solved the problem") os.chdir(systemvariables.read("exepath"))
def reg(args): string = args[0] stringprt = string ifvar = False i = 0 endstring = "" #print(stringprt.find("$", 0, 1)) # See if the first character of a string is a dollar sign, the symbol that declares the want of a # system variable, but ONLY if system variable varTrans is false. if (systemvariables.read("varTrans") == False): if (stringprt.find("$", 0, 1) == 0): ifvar = True else: ifvar = False else: ifvar = False # If there is a dollar sign, find out what variable we want and print it out. If not, print out # inputted text for j in args: if ((args[i] == ">") or (args[i] == ">>")): break if (ifvar == True): newstr = stringprt[1:] #print(newstr) if (systemvariables.lookupIndex(newstr) == -1): if (endstring != ""): endstring = endstring + " " + args[i] else: endstring = args[i] else: if (endstring != ""): endstring = endstring + " " + systemvariables.read(newstr) else: endstring = systemvariables.read(newstr) else: if (endstring != ""): endstring = endstring + " " + args[i] else: endstring = args[i] i += 1 flag = 0 tofile.write(args, endstring)
def get(): os.chdir(systemvariables.read("settingspath")) username = input("What do you want your user name to be? # ") namefile = open("Settings/ivhzadgz.bws", "w") namefile.write(username) namefile.close password = input("What Password? # ") passfile = open("Settings/kvnnadgz.bws", "w") passfile.write(password) passfile.close
def docs(): print("Solving Problems") os.chdir(systemvariables.read("HOME")) mkdir.create(["Documents"]) if (os.path.exists("Documents") == True): print( "Success! Note: Anything that was in the Documents folder before was deleted." ) return True else: systemvariables.modifyVoid("USRDOCS", "null") print("Failed. USRDOCS Variable set as null.") return False
def vars(args): output = "" for i in systemvariables.varsNames: output = output + i + ": " + str(systemvariables.read(i)) + "\n" output = output + "directorystack: " + str(systemvariables.directorystack) flag = 0 if (">>" in args): flag = 1 tofile.write(output, args[1]) elif (">" in args): if (flag == 0): tofile.write(output, args[1]) else: print(output)
def checkpassword(): if (systemvariables.lookupIndex("usrsession") == -1): print( "ERROR: Bash for Windows has ran into a critical error and must shutdown.\nError: USRSESSION_VAR_UNDEFINED" ) time.sleep(3) exit(1) session = systemvariables.read("usrsession") user = "" incorrect = True if (os.path.exists("Settings/ivhzadgzzoneth.bws") == True): potentialusr1 = open("Settings/ivhzadgzzoneth.bws" + "r") if (session == potentialusr1.read()): user = "******" potentialusr2 = open("Settings/ivhzadgz.bws", "r") if (session == potentialusr2.read()): user = "******" else: user = "******" if (user != "No User"): if (user == "Settings/ivhzadgzzoneth.bws"): while (incorrect == True): password = open("Settings/kvnnadgzzoneth.bws", "r") passguess = input("password # ") if (passguess == password.read()): incorrect = False else: print("Incorrect Password.") else: while (incorrect == True): password = open("Settings/kvnnadgz.bws", "r") passguess = input("password # ") if (passguess == password.read()): incorrect = False else: print("Incorrect Password.") else: logon()
def settingsrepair(): print("Solving Problems...") os.chdir(systemvariables.read("exepath") + "/../..") os.mkdir("Settings") username.get() os.chdir(systemvariables.read("exepath") + "/../..")
def go(args): path = str(args[0]) currentdir = os.getcwd() otherdir = systemvariables.read("lastdir") # If we have inputed something special, go to a special place. # If not, go to where directed. if (path == "~"): os.chdir(systemvariables.read("HOME")) elif (path == "-"): if (systemvariables.read("lastdir") == ""): print("bash: cd: $lastdir not set") else: os.chdir(systemvariables.read("lastdir")) elif (path == "/"): os.chdir(systemvariables.read("ROOT")) elif (path == "$settingspath"): os.chdir(systemvariables.read("settingspath")) elif (path == "$exepath"): os.chdir(systemvariables.read("exepath")) elif (path == "/Bash"): os.chdir(systemvariables.read("bshpath")) elif (path == "/Bash/Bash"): os.chdir(systemvariables.read("settingspath")) elif (path == "/Bash/Users"): os.chdir(systemvariables.read("usrpath")) elif (path == "/Bash/Bash/Settings"): os.chdir(systemvariables.read("loginfopath")) elif (path == "/Bash/Bash/Source"): os.chdir(systemvariables.read("srcpath")) elif (path == "/Bash/Bash/Source/Include"): os.chdir(systemvariables.read("exepath")) elif (path == "$bshpath"): os.chdir(systemvariables.read("bshpath")) elif (path == "$usrpath"): os.chdir(systemvariables.read("usrpath")) elif (path == "$loginfopath"): os.chdir(systemvariables.read("loginfopath")) elif (path == "$srcpath"): os.chdir(systemvariables.read("srcpath")) elif (path == "$USRDOCS"): if (systemvariables.read("USRDOCS") == "null"): print("bash: cd: null: No such file or directory") else: os.chdir(systemvariables.read("USRDOCS")) else: if (path == ""): go("~") else: if (os.path.exists(path) == True): os.chdir(path) else: print("bash: cd:", path + ": No such file or directory") # Set the lastdir system variable systemvariables.modifyVoid("lastdir", currentdir) if (os.getcwd() == systemvariables.read("lastdir")): systemvariables.modify("lastdir", otherdir)
def show(args): # Store all output in a variable output = "" # If we don't request to list the current directory and don't want to send output of current # directory to file, do the following: if ((args[0] != "") and ((args[0] != ">") and (args[0] != ">>"))): # Make sure the directory requested exists and that it is a directory if ((os.path.exists(args[0]) == True) and (os.path.isdir(args[0]) == True)): # Remember what directory we are currently in then change to the requested directory. lastDir = os.getcwd() os.chdir(args[0]) # Get a listing fo what is in the directory, then list them in a fancy way dir_list = os.listdir(os.getcwd()) hold = [] i = 0 j = 0 for dirs in dir_list: # Debug message if it is enabled if (systemvariables.read("debugMsg") == 1): print( systemvariables.color.YELLOW + systemvariables.color.BOLD + "[Debug]" + systemvariables.color.END + " ls:", os.path.isdir(str(dir_list[i]))) if (os.path.isdir(dir_list[i]) == True): if (i == len(dir_list) - 1): output = output + dir_list[i] + " [DIR]" else: output = output + dir_list[i] + " [DIR]\n" else: hold.append(dir_list[i]) i += 1 for k in hold: if (j == len(hold) - 1): output = output + hold[j] else: output = output + hold[j] + "\n" j += 1 # Go to the directory we were just in. os.chdir(lastDir) # If asked to do so, send output to a file. Either overwrite a file or append to it. if (">>" in args): i = 0 index = 0 for j in args: if (i == 0): i += 1 continue if (args[i] == ">>"): index = i + 1 break i += 1 tofile.write(output, args[index]) elif (">" in args): i = 0 index = 0 for j in args: if (i == 0): i += 1 continue if (args[i] == ">"): index = i + 1 break i += 1 tofile.write(output, args[index]) # If we don't want to send output of command to a file, print the output to the screen. else: print(output) else: # Error Message: if it is a file repeat file name if (os.path.isfile(args[0]) == True): print(args[0]) else: print("ls: cannot access '" + args[0] + "': No such file or directory") # Either print listing of current directory or send output of command to file. # Pretty much the same as before. elif ((args[0] == "") or (args[0] == ">") or args[0] == ">>"): dir_list = os.listdir(os.getcwd()) hold = [] i = 0 j = 0 for dirs in dir_list: # Debug message if it is enabled if (systemvariables.read("debugMsg") == 1): print( systemvariables.color.YELLOW + systemvariables.color.BOLD + "[Debug]" + systemvariables.color.END + " ls:", os.path.isdir(str(dir_list[i]))) if (os.path.isdir(dir_list[i]) == True): if (os.path.isdir(dir_list[i]) == True): if (i == len(dir_list) - 1): if (len(hold) == 0): output = output + dir_list[i] + " [DIR]" else: output = output + dir_list[i] + " [DIR]\n" else: output = output + dir_list[i] + " [DIR]\n" else: hold.append(dir_list[i]) i += 1 for k in hold: if (j == len(hold) - 1): output = output + hold[j] else: output = output + hold[j] + "\n" j += 1 if (">>" in args): tofile.write(output, args[1]) elif (">" in args): tofile.write(output, args[1]) else: print(output)
def logon(): # If the prompt.bws file doesn't exist, call on repair script to initialize one. if (os.path.exists("prompt.bws") == False): if (repair.promptInit(os.getcwd()) == 1): os.system("cls") print( "Bash for Windows has run into a non-critical error:\nPROMPT_NOT_ACCESSABLE\n\n\ This is not a critical error, so Bash for Windows will continue to work ok,\nminus some optional \ functionality.") choice = input( "Do you want to contnue using Bash for Windows? [y,N] ") if (choice.upper() != "Y"): exit(1) # Initialize variables with default values systemvariables.init("debugMsg", 0) systemvariables.init("varTrans", 0) systemvariables.init("colorPrompt", 0) else: # Check again to make sure we are running Windows oschk.check() os.chdir(systemvariables.read("exepath")) os.chdir("../../") incorrect = True while (incorrect == True): user = open("Settings/ivhzadgz.bws", "r") userguess = input(socket.gethostname() + " login: "******"Incorrect Username.") incorrect = True # Check double check to make sure we are running Windows if (platform.system() != "Windows"): print( "Bash for Windows has seen that you are not using Windows. Launching Bash..." ) os.system("bash") exit() while (incorrect == True): password = open("Settings/kvnnadgz.bws", "r") passguess = input("Password # ") if (passguess == password.read()): incorrect = False systemvariables.init("usrsession", userguess) else: print("Incorrect Password.") password.close() print("Welcome to Bash(the Bourne Again Shell) for Windows!") while (True): # Load in prompt.bws variables os.chdir(systemvariables.read("settingspath") + "/Settings") # Store the contents of the prompt.bws file into memory file = open("prompt.bws", "r") promptConfigTxt = file.read() file.close() txtOnLine = [""] j = 0 # Store each line of text in an array for i in promptConfigTxt: if (i == "\n"): txtOnLine.append("") j += 1 continue txtOnLine[j] = txtOnLine[j] + i # Seperate each value with equals sign and put them in a system variable, unless it has # a # as it's first character j = 0 l = 0 for i in txtOnLine: varNam = "" varConts = "" shift = 0 l = 0 for k in txtOnLine[j]: if ((l == 0) and (k == "#")): break if (k == "="): shift = 1 continue if (shift == 0): varNam = varNam + k else: varConts = varConts + k l += 1 if (varNam != ""): systemvariables.init(varNam, varConts) j += 1 # The varTrans variable's value should be converted into an integer, same for debugMsg and colorPrompt if ((systemvariables.read("varTrans") == "1")): systemvariables.modifyVoid("varTrans", 1) else: if (systemvariables.read("varTrans") != -1): systemvariables.modifyVoid("varTrans", 0) if ((systemvariables.read("debugMsg") == "1")): systemvariables.modifyVoid("debugMsg", 1) else: if (systemvariables.read("debugMsg") != -1): systemvariables.modifyVoid("debugMsg", 0) if ((systemvariables.read("colorPrompt") == "1")): systemvariables.modifyVoid("colorPrompt", 1) else: if (systemvariables.read("colorPrompt") != -1): systemvariables.modifyVoid("colorPrompt", 0) # We need to go to the parent directory os.chdir("..") # Check for autorun.bws file, and call a function to take care of the rest if (os.path.exists("Settings/autorun.bws") == False): if (os.path.exists("Settings/noauto.bws") == False): autorun = input( "Bash for Windows cannot find a autorun.bws file. Create one? (Y,n) " ) if ((autorun == "n") or (autorun == "N")): touch.write(["Settings/noauto.bws"]) else: touch.write(["Settings/autorun.bws"]) print( "autorun.bws file has been placed inside of the Bash/Bash/Settings folder." ) edit = input( "Would you like to modify the autorun.bws file? (Y,n) " ) if ((edit != "n") and (edit != "N")): nano.write(["Settings/autorun.bws"]) file = open("Settings/autorun.bws", "r") autoRun(str(file.read())) file.close() else: file = open("Settings/autorun.bws", "r") autoRun(str(file.read())) file.close() user.close() if (bash.run() == 0): if (systemvariables.read("restart") == 1): os.chdir(systemvariables.read("tmppath")) file = open("lastcwd.bws", "r") todir = file.read() file.close() systemvariables.modifyVoid("startDir", str(todir)) continue break
def runcmd(command): # Find a space. If one is found, put it in another variable. args = command.find(" ", 0, len(command)) argsArr = [''] # Counters i = 0 j = 0 k = 0 flag = 0 flag2 = 0 # Only do it if there is indeed a space if (args != -1): for i in command: # Only do this after a space if (j > args): # If the character is \, set a flag and remove the \. If not, turn off the flag if (i == "\\"): flag = 1 if (i == "\\"): continue # If we come across a space, add an item to the array of arguments and skip the rest, # unless the flag set before is set if ((i == " ") and (flag == 0)): k += 1 argsArr.append("") continue elif ((i == " " and (flag == 1))): flag = 0 # Take the current item in the args array and put in each character of the input # string, then delete that same character from the input string argsArr[k] = argsArr[k] + i command = command[0:j:] else: j += 1 # Reset the counters i = 0 j = 0 k = 0 # If we have at least 1 space, make sure you take out the last character # in the command variable that happens to be a space if (args != -1): command = command[:-1:] # If the value set in the system variable "varTrans" is set to true, then replace all # variables with their values. First, make sure it exists. varTrans = systemvariables.read("varTrans") j = 0 l = 0 i = 0 if (varTrans != -1): if (varTrans == 1): for i in argsArr: var = 0 varNam = "" k = "" for k in argsArr[j]: # If this is the first character and it is a $, we are setting up to look # at a possible variable. if ((l == 0) and (k == "$")): var = 1 l += 1 continue if ((l >= 0) and (var != 1)): break else: varNam = varNam + k # Check to make sure the variable called for exists. If it does, set this argument # to be the value in the variable. if (systemvariables.read(varNam) != -1): argsArr[j] = systemvariables.read(varNam) j += 1 # Commands if (command == "exit"): os.chdir(systemvariables.read("tmppath")) conts = ls.list() for i in conts: try: if (os.path.isfile(i) == True): os.remove(i) elif (os.path.isdir(i) == True): shutil.rmtree(i) else: continue except Exception as e: print( "Bash for Windows has run into a non-critical issue: TMP_DEL_ERR\nThe Error message is:\ \n" + str(e), "\nThis occured while deleting file", i, "in the temp directory.\nPress Enter to Continue...") input("") continue print("Goodbye!") exit(0) elif (command == "ls"): ls.show(argsArr) elif (command == "cd"): cd.go(argsArr) elif (command == "pwd"): tofile.write(argsArr, os.getcwd()) elif (command == "cat"): cat.show(argsArr) elif (command == "nano"): file = argsArr nano.write(file) elif (command == "vi"): file = argsArr nano.write(file) elif (command == "vim"): file = argsArr nano.write(file) elif (command == "emacs"): file = argsArr nano.write(file) elif (command == "clear"): os.system("cls") elif (command == "lsvar"): ls.vars(argsArr) elif (command == "echo"): echo.reg(argsArr) elif (command == "touch"): touch.write(argsArr) elif (command == "rm"): rm.remove(argsArr) elif (command == "mv"): file = argsArr[0] dstfile = argsArr[1] mv.move(file, dstfile) elif (command == "cp"): cp.copy(argsArr) elif (command == "pushd"): path = argsArr pushd.go(path) elif (command == "popd"): popd.go() elif (command == "uname"): uname.list(argsArr) elif (command == "mkdir"): mkdir.create(argsArr) elif (command == "date"): date.show(argsArr) elif (command == "restart"): # Debug Message if (systemvariables.read("debugMsg") == 1): print(systemvariables.color.YELLOW + systemvariables.color.BOLD + "[Debug]" + systemvariables.color.END + " Bash: Restarting!") # Save current directory cwd = os.getcwd() os.chdir(systemvariables.read("tmppath")) file = open("lastcwd.bws", "w") file.write(str(cwd)) file.close() systemvariables.modifyVoid("restart", 1) return 0 else: if (argsArr[0] == "="): if (systemvariables.lookupIndex(command) == -1): systemvariables.init(command, argsArr[1]) else: systemvariables.modifyVoid(command, argsArr[1]) else: dirContents = ls.list() if (command == ""): sleep(0) elif (command in dirContents): if (".bwsh" in command): if (os.path.exists(command) == True): scriptContents = open(command, "r") script.run(str(scriptContents.read())) scriptContents.close() else: print(command + ": command not found") else: print(command + ": command not found") else: print(command + ": command not found")
def run(): # Check once again to make sure we are running Windows oschk.check() # Debug Message if (systemvariables.read("debugMsg") == 1): print(systemvariables.color.YELLOW + systemvariables.color.BOLD + "[Debug]" + systemvariables.color.END + " Bash: Starting!") os.chdir(systemvariables.read("exepath")) os.chdir("../../../../") systemvariables.init("ROOT", os.getcwd()) os.chdir("Bash/Users/" + systemvariables.read("usrsession")) systemvariables.init("HOME", os.getcwd()) if (os.path.exists("Documents") == False): print("Unfortunatly, Bash for Windows cannot find your documents.") prompt = input("Do you want to try to repair the problem? [Y,n] ") if (prompt == "n"): print("Abort.") systemvariables.init("USRDOCS", "null") elif (prompt == "N"): print("Abort.") systemvariables.init("USRDOCS", "null") else: success = repair.docs() if (success == True): os.chdir("Documents") systemvariables.init("USRDOCS", os.getcwd()) else: os.chdir("Documents") systemvariables.init("USRDOCS", os.getcwd()) os.chdir(systemvariables.read("settingspath")) systemvariables.modify("settingspath", os.getcwd()) os.chdir("Settings") systemvariables.init("loginfopath", os.getcwd()) os.chdir("../Source") systemvariables.init("srcpath", os.getcwd()) os.chdir("../../Users") systemvariables.init("usrpath", os.getcwd()) os.chdir("..") systemvariables.init("bshpath", os.getcwd()) # Debug Message if (systemvariables.read("debugMsg") == 1): print(systemvariables.color.YELLOW + systemvariables.color.BOLD + "[Debug]" + systemvariables.color.END + " Bash: " + os.getcwd()) os.chdir("temp") systemvariables.init("tmppath", os.getcwd()) os.chdir("..") # If we want to restart Bash for Windows, we'll need this variable. systemvariables.modifyVoid("restart", 0) # Get user name cd.go("/") user = open("Bash/Bash/Settings/ivhzadgz.bws", "r") usr = user.read() user.close() # Get back to "Home" folder cd.go("~") # If the system variable for the last directory exists, go to that directory # (in case of restart) if (systemvariables.read("startDir") != -1): os.chdir(systemvariables.read("startDir")) # Reset the lastdir variable systemvariables.modify("lastdir", "") # If the user has used Ctrl + C, quit without crashing try: # Do this until told to exit while (True): # Change display depending on where the user is in the file system if (os.getcwd() == systemvariables.read("ROOT")): display = "/" elif (os.getcwd() == systemvariables.read("HOME")): display = "~" elif (os.getcwd() == systemvariables.read("USRDOCS")): display = "~/Documents" elif (os.getcwd() == systemvariables.read("settingspath")): display = "/Bash/Bash" elif (os.getcwd() == systemvariables.read("loginfopath")): display = "/Bash/Bash/Settings" elif (os.getcwd() == systemvariables.read("srcpath")): display = "/Bash/Bash/Source" elif (os.getcwd() == systemvariables.read("usrpath")): display = "/Bash/Users" elif (os.getcwd() == systemvariables.read("exepath")): display = "/Bash/Bash/Source/Include" elif (os.getcwd() == systemvariables.read("bshpath")): display = "/Bash" else: display = os.getcwd() # Prompt. If color prompt is enabled, use color. if (systemvariables.read("colorPrompt") == 1): command = input(systemvariables.color.BOLD + systemvariables.color.GREEN + usr + "@" + socket.gethostname() + systemvariables.color.END + ":" + systemvariables.color.BOLD + systemvariables.color.BLUE + display + systemvariables.color.END + "$ ") else: command = input(usr + "@" + socket.gethostname() + ":" + display + "$ ") # Run the command using the function above. if (runcmd(command) == 0): return 0 except KeyboardInterrupt: # If the program gets a interrupt, exit without crashing exit()
os.chdir("Bash/Bash/Source/Include") import bash import os.path import username import usrmgr import repair import systemvariables import time # The commented out lines are for me to use for debugging purposes only. #print(os.getcwd()) #print(os.path.dirname(os.path.realpath(__file__))) # Set a system variable systemvariables.init("exepath", os.getcwd()) systemvariables.init("settingspath", systemvariables.read("exepath") + "/../..") # Check to make sure we are running on Windows and if not start bash if(platform.system() != "Windows"): print("Bash for Windows has seen that you are not using Windows. Launching Bash...") os.system("bash") exit() # Move to the root of the file structure os.chdir(systemvariables.read("exepath") + "/../..") #print(os.getcwd()) os.chdir("../..") #print(os.getcwd()) #print(os.path.exists("Bash/Users")) # See if any folders are deleted and if they are attempt to fix it using the repair script
def remove(args): i = 0 # Check for Wildcards wildCard = False wildIndex = [] for j in args: if ("*" in args[i]): wildCard = True wildIndex.append(i) i += 1 # Figure out if the wildcard has a dot, if it is before dot, or after dot if (wildCard == True): dot = -1 flag = 0 k = 0 l = 0 m = 0 i = 0 for i in wildIndex: for j in args[i]: if (j == "*"): l = k if (j == "."): flag = 1 m = k k += 1 if (flag == 0): dot = -1 elif (l > m): dot = 1 elif (l < m): dot = 0 # Reset Variable i = 0 if ("-r" in args): lastIndex = len(args) - 1 if (args[0] == "-r"): args.pop(0) for j in args: file = args[i] if (os.path.exists(file)): # Make sure it's' a directory if (os.path.isdir(file) == True): if (os.getcwd() == systemvariables.read("HOME")): if (file == "Documents"): force = input( "rm: remove write-protected directory '" + file + "'? ") if ((force == "y") or (force == "Y")): shutil.rmtree(file) else: shutil.rmtree(file) else: shutil.rmtree(file) else: print("rm: cannot remove '" + file + ": No such file or directory") else: print("rm: cannot remove '" + file + ": No such file or directory") i += 1 elif (args[lastIndex] == "-r"): args.pop(lastIndex) for j in args: file = args[i] if (os.path.exists(file)): # Make sure it isn't a directory if (os.path.isdir(file) == True): shutil.rmtree(file) else: os.remove(file) else: print("rm: cannot remove '" + file + ": No such file or directory") i += 1 else: for j in args: file = args[i] # If it exists, remove it. If not, display a message if (os.path.exists(file)): # Make sure it isn't a directory if (os.path.isfile(file) == True): os.remove(file) else: print("rm: cannot remove '" + file + ": Is a directory") # If we found a wildcard before, do the following depending on where the dot is elif (wildCard == True): if (dot == -1): # Remove all files in the directory dirList = ls.list() n = "" for n in dirList: if (os.path.isdir(n) == True): print("rm: cannot remove '" + n + ": Is a directory") else: os.remove(n) elif (dot == 0): # Remove all files with the extension we asked for k = 0 flag = 0 ext = "" n = "" for n in args[k]: if (k == l): flag = 1 k += 1 continue if (flag == 1): ext = ext + n k += 1 k = 0 n = "" dirList = ls.list() for n in dirList: if (ext in n): if (os.path.isdir(n) == True): print("rm: cannot remove '" + n + ": Is a directory") else: os.remove(n) else: # Remove all files with the filename we asked for n = "" k = 0 name = "" for n in args[i]: if (n == "."): name = name + n break name = name + n dirList = ls.list() n = "" for n in dirList: if (name in n): if (os.path.isdir(n) == True): print("rm: cannot remove '" + n + ": Is a directory") else: os.remove(n) else: print("rm: cannot remove '" + file + ": No such file or directory") i += 1