2. Function name: find_file_in_folder Parameters: The first…
Question Answered step-by-step 2. Function name: find_file_in_folder Parameters: The first… 2. Function name: find_file_in_folder Parameters: The first parameter should be a string with a file name in it, like AAA’. The second parameter is a string with a folder to look in for a file with that search name, or it can also be a single Ale. The third parameter is the relative path to that file or folder, like or “f1”. Return value: True if a file is found with the name being searched for in the second parameter. Comment You will want to look very carefully at the file example from class, where we counted the number of files, not folders. That was a recursive accumulation loop. This is a recursive search loop. As an example, using the provided folder structure in the starter code, find_file_in_folder(“A.txt”, “f1”, “I would return True find file in folder(12″,11″,”I would return False, since f2 is a folder. not a file find file in folderrA.txt”, .A.txt.,11.1would return True as A.txt can be found in A.txt starting in the fl folder. This is the problem in question that I am having trouble with. With another tutor, we came up with this code for the function. def find_file_in_folder(file, folder, path): “”” return true if the folder is found in the second parameter, false otherwise. :param file:string with filename :param folder:folder name to look for :param path:path to look for :return:True or False “”” for item in os.listdir(folder): if item == file: if item == path: return True else: return False I am still having trouble with testing the code to make sure it works. print(find_file_in_folder(“A.txt”, “f1”, “”)) print(find_file_in_folder(“b.txt”, “f1”, “”)) These are the two tests I ran and both failed. This is the error I get when I run the function. File “C:UsersjordcAppDataLocalTempA10files.py”, line 31, in find_file_in_folder for item in os.listdir(folder): FileNotFoundError: [WinError 3] The system cannot find the path specified: ‘f1’ Will this function go into my files? That is where I have the files that the test code is running? Also, I believe I need to make the function using recursion. I am not sure how to do that. Computer Science Engineering & Technology Python Programming CS 1400 Share QuestionEmailCopy link Comments (0)


