You can download this code by clicking the button below.
This code is now available for download.
This function lists all files in a specified directory, including files in subdirectories.
Technology Stack : os, os.walk
Code Type : Function
Code Difficulty :
import os
import re
def list_files_in_directory(directory_path):
"""
列出指定目录下的所有文件。
"""
files = []
for root, dirs, filenames in os.walk(directory_path):
for filename in filenames:
files.append(os.path.join(root, filename))
return files