You can download this code by clicking the button below.
This code is now available for download.
This function recursively lists all files in the specified path and returns a list of file objects.
Technology Stack : Pathlib, Recursion
Code Type : Recursive file list generation
Code Difficulty : Intermediate
def list_files_recursively(path):
from pathlib import Path
import os
def _list_files(p):
for child in p.iterdir():
if child.is_file():
yield child
elif child.is_dir():
yield from _list_files(child)
return list(_list_files(Path(path)))