How do I get a list of all files (and directories) in a given directory in Python?



How do I get a list of all files (and directories) in a given directory in Python?..

Answer / Anoop Singh

You can get a list of all files and directories in a given directory using the os module's listdir() function. For example: nimport osndir_path = '/my/directory'ndirs_and_files = os.listdir(dir_path)

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

Write a program in python to execute the bubble sort algorithm.

1 Answers  


Can I learn python without knowing html?

1 Answers  


How to create a unicode string in python?

1 Answers  


Is self a keyword in python?

1 Answers  


What are membership operators in python?

1 Answers  


Differentiate between the append() and extend() methods of a list?

1 Answers  


Do python arrays start at 0 or 1?

1 Answers  


How do I start learning python?

1 Answers  


How will you locally save an image using its url address?

1 Answers  


What are the types of inheritance in python?

1 Answers  


What is setup script?

1 Answers  


Does python have private?

1 Answers  


Categories