Let's assume that I have the following nested directories structure:
my_dir
|---- dir_1
|---- dir_2
|---- dir_3
|---- dir_4
|---- dir_5
|---- dir_6
|---- my_file.txt
How can I look if my_file.txt
exists in any of the sub-directories of dir_3
(e.g. dir_4
, dir_5
, dir_6
), and if exists how can I get its path? At the moment I tried with:
def file(name, path):
for r, d, f in os.walk(abspath(path)):
if name in files:
return os.path.join(r, n)
else:
return 'file not found'
However, the above function is odd. How can I do the same with Pathlib?