You can download this code by clicking the button below.
This code is now available for download.
This function is used to get a list of all files in a specified directory.
Technology Stack : os, re
Code Type : Function
Code Difficulty : Intermediate
import os
import re
def get_files_in_directory(path):
"""
获取指定目录下的所有文件列表。
Args:
path (str): 目录路径。
Returns:
list: 包含目录下所有文件名的列表。
"""
files = []
for item in os.listdir(path):
if os.path.isfile(os.path.join(path, item)):
files.append(item)
return files