You can download this code by clicking the button below.
This code is now available for download.
This function retrieves a list of filenames from a specified directory and returns a list containing these filenames.
Technology Stack : os
Code Type : Function
Code Difficulty :
import os
import re
def get_files_from_directory(directory_path):
"""
获取指定目录下的所有文件名列表。
:param directory_path: str, 指定目录的路径
:return: list, 包含目录下所有文件名的列表
"""
files = []
for root, dirs, filenames in os.walk(directory_path):
files.extend(filenames)
return files