How do I list all files of a directory?
@lebyy▲ 0 net votes
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…