AmanSehgal
Honored Contributor III

You can use a recursive function to list everything within a directory path, and then add a filter for .py files.

def get_dir_content(ls_path):
    for dir_path in dbutils.fs.ls(ls_path):
        if dir_path.isFile():
            yield dir_path.path
        elif dir_path.isDir() and ls_path != dir_path.path:
            yield from get_dir_content(dir_path.path)
    
list(get_dir_content('dbfs:/FileStore'))

Source: stackvoerflow