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 names of all files in the directory.
Technology Stack : os, re
Code Type : Function
Code Difficulty : Intermediate
import os
import re
def find_files_in_directory(directory):
"""
This function finds all files in the given directory and returns their names.
:param directory: str, the path to the directory to search in
:return: list of str, the names of the files in the directory
"""
return [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]