10

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?

0

1 Answer 1

6

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!

Sign up to request clarification or add additional context in comments.

4 Comments

Might want to be careful with backslashes in paths as they conflict with string escape characters.
Therefore, put "r" before the string: list = listdir(r"C:\Users\Hello\World\Python Programs")
Umm... answering your own question is encouraged if you figure out the answer in the meantime, but... why are you acting as if you're two people? (e.g., w/ "Good luck!")
@MuMind, well, the good luck is just an expression which shouldn't be a matter to how the question is answered. :) if you want, you can edit the answer and remove it. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.