You can download this code by clicking the button below.
This code is now available for download.
This function takes a directory path as an argument and returns a list of all files in the directory and its subdirectories.
Technology Stack : os, re
Code Type : Function
Code Difficulty : Intermediate
import os
import re
def list_files_in_directory(directory_path):
"""
列出指定目录下的所有文件。
"""
if not os.path.isdir(directory_path):
return "Directory does not exist."
file_list = []
for root, dirs, files in os.walk(directory_path):
for file in files:
file_list.append(os.path.join(root, file))
return file_list