python

List all files of a directory using os Python

from os import listdir
from os.path import isfile, join

dirPath = "path/to/my/directory"
allFileAndFolders = listdir(dirPath)

allFiles = [f for f in allFileAndFolders if isfile(join(dirPath, f))]

You can use the os.listdir() method to list all files and folders inside a directory. You need to pass the directory path to this method and it will return you everything inside the directory.

Was this helpful?