Can someone help me create a function that will list all the files in a specific directory using the library pathlib?
Here I have:

I have
I expected that I would have one list with the paths above, but my code returns a nested list.
Here is my code:
from pathlib import Path
def searching_all_files(directory: Path):
file_list = []
for x in directory.iterdir():
if x.is_file():
file_list.append(x)
else:
file_list.append(searching_all_files(directory/x))
return file_list
p = Path('C:\\Users\\akrio\\Desktop\\Test')
print(searching_all_files(p))
Hope someone can fix me.
source
share