Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list directory using Python [duplicate]

Possible Duplicate:
how to list all files of a directory in python

How do I list all directory content using python and add it to a list?

like image 731
gwafito Avatar asked Sep 22 '12 07:09

gwafito


1 Answers

With Python, there so many ways to do this however, this one is the simplest i know.

Please check the comments for the specifics of the output.

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!

like image 134
gwafito Avatar answered Oct 24 '22 09:10

gwafito