I have a need to build a list of all the files (only files, no directories) in a folder and its subfolders. I'm using pathlib
like this
import pathlib
for filename in pathlib.Path(".").rglob("*"):
print(filename)
code above works great with one exception: it returns the path of subfolders too, but I only want the files. Here's an example:
My tree
./file_x
./file_y
./subfolder1/file_x
./subfolder1/file_y
Code returns
./file_x
./file_y
./subfolder1
./subfolder1/file_x
./subfolder1/file_y
What I need
./file_x
./file_y
./subfolder1/file_x
./subfolder1/file_y