Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a function find_file that accepts a full directory path parameter (i.e., C:Userscs401DesktopDocs) and a file name parameter (i.e., MyFile.txt) that recursively searches all folders

Create a function find_file that accepts a full directory path parameter (i.e., C:\Users\cs401\Desktop\Docs) and a file name parameter (i.e., MyFile.txt) that recursively searches all folders and subfolders under the provided path for the specified filename. When found, the full file pathname should be printed. Note there may be multiple files within a folder structure that match the specified name. If the file is not found, nothing should be printed. If listing the files in a folder results in a PermissionError skip that folder.

CODE IN "PYTHON"

Sample output:

find_file("C:\\Users\\cs401\\Desktop\\Docs", "build.xml")

C:\Users\asd\Desktop\Docs\Art\Arrays\build.xml

C:\Users\asd\Desktop\Docs\comm\Client\build.xml

C:\Users\asd\Desktop\Docs\hola105\build.xml

I have this code so far:

import os

def find_all(file_name, dir_path): file_list = [] for root, dirs, files in os.walk(dir_path): if file_name in files: file_list.append(os.path.join(root, file_name)) return file_list

dir_path = input("Enter directory to check file:") file_name = input("Enter filename:")

print(find_all(file_name,dir_path))

I need help in placing the "PERMISSION ERROR" and also printing in a NEW LINE each time it searches for a filename.

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_2

Step: 3

blur-text-image_3

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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

Improving Intercultural Communication?

Answered: 1 week ago

Question

2. The model is credible to the trainees.

Answered: 1 week ago