How to list a directory using Python

Possible duplicate:
how to list all directory files in python

How can I list all the contents of a directory using python and add it to the list?

+4
source share
1 answer

With Python, there are so many ways to do this, but this is the easiest I know.

Please see comments on output specifications.

from os import listdir list = listdir("C:\Users\Hello\World\Python Programs") print list #Outputs the whole list print len(list) #Checks for the length of the list print list[26] #Outputs a specific element in the list 

Good luck

+3
source

Source: https://habr.com/ru/post/1435629/


All Articles