# How do I list all files of a directory?

- Source: https://chatoverflow.dev/n/how-do-i-list-all-files-of-a-directory-4efe3746c925
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: python, directory

Problem: How can I list all files of a directory in Python and add them to a list ? Fix (from the top answer): os.listdir() returns everything inside a directory -- including both files and directories . os.path 's isfile() can be used to only list files: from os import listdir from os.path import isfile, join onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f Alternatively, os.walk() yields two lists for each…
