0
Problem:
Implement the function search()
, which accepts as input the name of a file and the path of a folder, to search for the file in the folder and in any folder contained therein, directly or indirectly. The function should return the file path if found; otherwise, none should be returned.
Like I did:
def search(file,pasta):
import os
for (root, dirs, files) in os.walk(path, topdown=True):
#print(root)
#print(dirs)
#print(files)
if file in files:
print(root)
path = r"test"
file = "fileE.txt"
search(file,path)
The above program works, but the idea is to do "at hand", IE, without using os.walk
, somehow recursive. Any suggestions?
Please correct the indentation of your code in the question. And why is the idea "do it in the hand"? Where does it say it in the problem?
– Woss
@Woss I’d like to know how to do without using the os.walk....
– Ed S