You can download this code by clicking the button below.
This code is now available for download.
This function recursively searches for all files in the specified directory and its subdirectories, and returns a list of all file paths.
Technology Stack : os, os.walk
Code Type : Function
Code Difficulty : Beginner
import os
import re
def find_files_in_directory(directory_path):
"""
递归地在指定目录下找到所有文件,并返回它们的路径列表。
"""
file_paths = []
for root, dirs, files in os.walk(directory_path):
for file in files:
file_paths.append(os.path.join(root, file))
return file_paths