Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

from pathlib import Path def pathdirectory ( directory ) : Pathsd = Path ( directory ) if Pathsd.exists ( ) : Paths = [ ]

from pathlib import Path
def pathdirectory(directory):
Pathsd = Path(directory)
if Pathsd.exists():
Paths =[]
files =[]
direct =[]
for item in sorted(Pathsd.iterdir()):
if item.is_file():
files.append(item)
elif item.is_dir():
direct.append(item)
Paths.extend(files)
Paths.extend(direct)
for path in Paths:
print(path)
def recursive(directory):
Pathsd = Path(directory)
if Pathsd.exists():
print(directory)
for item in sorted(Pathsd.iterdir()):
if item.is_file():
print(item)
elif item.is_dir():
recursive(item)
def files_list(directory):
Pathsd = Path(directory)
if Pathsd.exists():
for item in sorted(Pathsd.iterdir()):
if item.is_file():
print(item)
def search_files(directory, search):
Pathsd = Path(directory)
if Pathsd.exists():
for item in sorted(Pathsd.iterdir()):
if item.is_file() and search in item.name:
print(item)
def filter(directory, extension):
Pathsd = Path(directory)
if Pathsd.exists():
for item in sorted(Pathsd.iterdir()):
if item.is_file() and (item.suffix == extension or item.suffix =='.'+ extension):
print(item)
def command_options(directory, options, parameter = None):
if '-r' in options:
recursive(directory)
if '-f' in options:
files_list(directory)
if '-s' in options:
search_files(directory, parameter)
if '-e' in options:
filter(directory, parameter)
def main():
while True:
user_input = input('[COMMAND][INPUT][[-]OPTION][INPUT]')
if user_input.upper()=='Q':
break
user_split = user_input.split('',3)
if len( user_split)==2:
command, directory = user_split[0].upper(), user_split[1]
if command =='L':
pathdirectory(directory)
elif len( user_split)==3:
command, directory, options = user_split[0].upper(), user_split[1], user_split[2]
if command =='L':
command_options(directory, options)
elif len(user_split)==4:
command, directory, options, parameter = user_split[0].upper(), user_split[1], user_split[2], user_split[3]
if command =='L':
command_options(directory, options, parameter)
if __name__=="__main__":
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 /home/algol/ics32/-r -s Schedule.txt
And the resulting output:
/home/algol/ics32/Schedule.txt
/home/algol/ics32/assignments/Schedule.txt
/home/algol/ics32/laboratories/Schedule.txt
/home/algol/ics32/lectures/Schedule.txt
/home/algol/ics32/workoutprojects/Schedule.txt
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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

List and describe six costs of inflation.

Answered: 1 week ago

Question

22. Prove Theorem 6.3.3.

Answered: 1 week ago

Question

Differentiate between gender equality and gender equity.

Answered: 1 week ago