Answered step by step
Verified Expert Solution
Question
1 Approved Answer
from pathlib import Path def pathdirectory ( directory ) : Pathsd = Path ( directory ) if Pathsd.exists ( ) : Paths = [ ]
from pathlib import Path
def pathdirectorydirectory:
Pathsd Pathdirectory
if Pathsd.exists:
Paths
files
direct
for item in sortedPathsditerdir:
if item.isfile:
files.appenditem
elif item.isdir:
direct.appenditem
Paths.extendfiles
Paths.extenddirect
for path in Paths:
printpath
def recursivedirectory:
Pathsd Pathdirectory
if Pathsd.exists:
printdirectory
for item in sortedPathsditerdir:
if item.isfile:
printitem
elif item.isdir:
recursiveitem
def fileslistdirectory:
Pathsd Pathdirectory
if Pathsd.exists:
for item in sortedPathsditerdir:
if item.isfile:
printitem
def searchfilesdirectory search:
Pathsd Pathdirectory
if Pathsd.exists:
for item in sortedPathsditerdir:
if item.isfile and search in item.name:
printitem
def filterdirectory extension:
Pathsd Pathdirectory
if Pathsd.exists:
for item in sortedPathsditerdir:
if item.isfile and itemsuffix extension or item.suffix extension:
printitem
def commandoptionsdirectory options, parameter None:
if r in options:
recursivedirectory
if f in options:
fileslistdirectory
if s in options:
searchfilesdirectory parameter
if e in options:
filterdirectory parameter
def main:
while True:
userinput inputCOMMANDINPUTOPTIONINPUT
if userinput.upperQ:
break
usersplit userinput.split
if len usersplit:
command, directory usersplitupper usersplit
if command L:
pathdirectorydirectory
elif len usersplit:
command, directory, options usersplitupper usersplit usersplit
if command L:
commandoptionsdirectory options
elif lenusersplit:
command, directory, options, parameter usersplitupper usersplit usersplit usersplit
if command L:
commandoptionsdirectory options, parameter
if namemain:
main
Within our code we are trying to accomplish
Or with the recursion option in a slightly different folder, just for the sake of demonstration:
L homealgolicsr s Schedule.txt
And the resulting output:
homealgolicsScheduletxt
homealgolicsassignmentsScheduletxt
homealgolicslaboratoriesScheduletxt
homealgolicslecturesScheduletxt
homealgolicsworkoutprojectsScheduletxt
We are trying to make the program be able to use two commands, both r and s together or even r and f together basically where our commands have a recursive option rather than standalone commands of f or s or even e
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