How to Use the os Module to List Files in a Directory

import os

directory_path = "./"
files_in_directory = [file for file in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, file))]
print(f"Files in '{directory_path}': {files_in_directory}")

Leave a Comment

Your email address will not be published.