Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import sys import os from os import listdir from os.path import isfile, join from os.path import isdir import csv import shutil from pathlib import Path
import sys import os from os import listdir from os.path import isfile, join from os.path import isdir import csv import shutil from pathlib import Path from os import walk def display_menu(): # here is the menu for our display print("The File Manager program") print() print("COMMAND MENU") print("add - add a folder/subfolder") print("exit - Exit program") print() def add(fm_list): while True: msg = input("What do you want to create?: " " Insert 1 for Folder " " Insert 2 for Subfolder. ") if msg == "1": folder = input("Name of the folder: ") choice = input("Do you want to add a subfolder to this folder?: (y/n): ") if choice.lower() == "y": fm_list.append(folder) os.chdir('F:\\Test') # this path is our test path where folders, subfolders and files will be stored os.makedirs(folder, exist_ok=True) subfolder = input("Name of the subfolder: ") fm_list.append(subfolder) os.chdir('F:\\Test\\' + folder) # here we concatenate the folder # already created then we create the subfolder on the next line os.makedirs(subfolder, exist_ok=True) print(folder + " was added to the list of folder.") print(subfolder + " was added to " + folder) break elif choice == "n": os.chdir('F:\\Test') fm_list.append(folder) os.chdir('F:\\Test') os.makedirs(folder, exist_ok=True) print(folder + " was added to the list of folder.") print("Your folder path is : " + str(Path.cwd())) break else: print("Please choose between (y/n) ") elif msg == "2": store = input("Where do you want to store your subfolder?: " " Insert A to store it in the DEFAULT folder" " Insert B to store it in a new folder ") if store.lower() == "a": subfolder = input("What is the name of the subfolder: ") fm_list.append(subfolder) print("Your subfolder will be store to the Default folder: ") os.chdir('F:\\Test\\Default') # this is the Default folder already in the test directory os.makedirs(subfolder, exist_ok=True) print(subfolder + " was added to the folder named Default") break elif store.lower() == "b": folder = input("Name of the folder: ") fm_list.append(folder) os.chdir('F:\\Test') os.makedirs(folder, exist_ok=True) subfolder = input("Name of the subfolder: ") fm_list.append(subfolder) os.chdir('F:\\Test\\' + folder) os.makedirs(subfolder, exist_ok=True) print(folder + " was added to the list of folder.") print(subfolder + " was added to " + folder) break else: print("Invalid entry!!! ") continue def main(): fm_list = [] display_menu() while True: command = input("Command: ") if command.lower() == "add": add(fm_list) elif command.lower() == "exit": break else: print("Not a valid command. ") if __name__ == '__main__': main()
Thanks in advance for the answers. I have my function here, I would like when I hit the stage of the elif msg == 2...when the user inputs anything else other than the available options (a or b) then he gets prompt back to choose the appropriate option (In other words, I give the hand again and ask the user where to store the subfolder)...instead it does prompt back at the beginning of the code... msg = input("What do you want to create?: " " Insert 1 for Folder " " Insert 2 for Subfolder. ") ...Thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started