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.
Technology Stack : os, list, os.listdir, os.path.isfile, list comprehension
Code Type : Function
Code Difficulty :
import os
import re
def list_files_in_directory(directory):
"""
List all files in a given directory.
:param directory: The directory path to list files from.
:return: A list of filenames in the given directory.
"""
return [file for file in os.listdir(directory) if os.path.isfile(os.path.join(directory, file))]