How to list files directories in python

0 votes
Is there a way I can list the contents of a directory in python and use the list of files/directory one at a time than just printing them all at once?
Feb 4, 2019 in Python by Karan
212 views

1 answer to this question.

0 votes

You can use the os module to list the files and directories, and then use a for loop to use each files/directory. Refer to the following code:

import os
for filename in listdir(path/to/dir):
    #whatever code you want

answered Feb 4, 2019 by Omkar
• 69,210 points

Related Questions In Python

+3 votes
5 answers

How to read multiple data files in python

Firstly we will import pandas to read ...READ MORE

answered Apr 6, 2018 in Python by DeepCoder786
• 1,720 points
13,954 views
+1 vote
12 answers
0 votes
1 answer

How to Print a List in Python

ou are using Python 2.x syntax with ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,710 points
498 views
0 votes
1 answer

How to Reverse a list in Python

You can use the reversed function in ...READ MORE

answered Sep 29, 2018 in Python by SDeb
• 13,300 points
459 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 3,138 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
2,338 views
0 votes
1 answer

How to list only text files in a directory using python?

Well, you are using a complex way. ...READ MORE

answered Feb 4, 2019 in Python by Omkar
• 69,210 points
1,964 views
0 votes
1 answer

How to list only files in a directory?

Before printing, you can use a check ...READ MORE

answered Feb 4, 2019 in Python by Omkar
• 69,210 points
208 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP