You can download this code by clicking the button below.
This code is now available for download.
This function walks through all files in the specified directory and returns a list containing all file paths.
Technology Stack : os, os.walk
Code Type : Function
Code Difficulty : Intermediate
import math
import os
import re
import shutil
import subprocess
import sys
import time
def list_files_in_directory(directory_path):
"""
List all files in a given directory.
Args:
directory_path (str): The path to the directory to list files from.
Returns:
list: A list of file names in the directory.
"""
files = []
for root, _, filenames in os.walk(directory_path):
for filename in filenames:
files.append(os.path.join(root, filename))
return files