Answered step by step
Verified Expert Solution
Question
1 Approved Answer
what is wrong with my coding: import os def main ( ) : while True: user _ input = input ( Enter command:
what is wrong with my coding: import os def main: while True: userinput inputEnter command: split if not userinput: continue command userinputupper if command Q: printExiting the program." break elif command L: if lenuserinput: printError: Please provide a directory path after L continue directory userinput options userinput: directorycontentsdirectory options else: printError: Invalid command. Use L to list contents or Q to quit." def directorycontentsdirectory options: try: filesanddir oslistdirdirectory if f in options: filesanddir item for item in filesanddir if ospath.isfileospath.joindirectory item if s in options: searchterm optionsoptionsindexs filesanddir item for item in filesanddir if searchterm in item if e in options: extension optionsoptionsindexe filesanddir item for item in filesanddir if item.endswith extension if r in options: for item in filesanddir: printospath.joindirectory item if ospath.isdirospath.joindirectory item: directorycontentsospath.joindirectory item options else: for item in filesanddir: printospath.joindirectory item except FileNotFoundError: printfError: Directory directory not found." if namemain: main
what is wrong with my coding: import os
def main:
while True:
userinput inputEnter command: split
if not userinput:
continue
command userinputupper
if command Q:
printExiting the program."
break
elif command L:
if lenuserinput:
printError: Please provide a directory path after L
continue
directory userinput
options userinput:
directorycontentsdirectory options
else:
printError: Invalid command. Use L to list contents or Q to quit."
def directorycontentsdirectory options:
try:
filesanddir oslistdirdirectory
if f in options:
filesanddir item for item in filesanddir if ospath.isfileospath.joindirectory item
if s in options:
searchterm optionsoptionsindexs
filesanddir item for item in filesanddir if searchterm in item
if e in options:
extension optionsoptionsindexe
filesanddir item for item in filesanddir if item.endswith extension
if r in options:
for item in filesanddir:
printospath.joindirectory item
if ospath.isdirospath.joindirectory item:
directorycontentsospath.joindirectory item options
else:
for item in filesanddir:
printospath.joindirectory item
except FileNotFoundError:
printfError: Directory directory not found."
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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