Fix Python – How can I list the contents of a directory in Python?

Question

Asked By – Paul D. Waite

Can’t be hard, but I’m having a mental block.

Now we will see solution for issue: How can I list the contents of a directory in Python?


Answer

import os
os.listdir("path") # returns list

This question is answered By – user85461

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0