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 that directory.
Technology Stack : os, list comprehension
Code Type : Function
Code Difficulty : Beginner
import os
import re
def list_files_from_directory(path):
"""
列出指定目录下的所有文件名。
:param path: str, 指定目录的路径
:return: list, 包含指定目录下所有文件名的列表
"""
files = []
for item in os.listdir(path):
if os.path.isfile(os.path.join(path, item)):
files.append(item)
return files