I need to traverse all my folders to find the file path of a folder with files with a specific extension (for sake of example, we will say .txt
).
I do not know if the folder will be at the top of the tree or at the bottom.
For example, we are starting in:
OneDrive/Documents/project/SourceCode
The folder containing all the .txt files could be in OneDrive/Documents/project/SourceCode/TxtFiles
or it could be in OneDrive/Documents/project/TxtFiles
or it could also be up more past the project file.
How would I find the filepath? I tried using os.walk
, but I do not have a strong enough understanding of how it works. In the end, I am globbing all of the .txt
files into a giant list.
I would recommend using
pathlib
: