Ask coding questions

← Back to all posts
Looping through n number of files using python
tankerguy1917 (178)

Is it possible to loop through n number files using python? I am working on a project with my brother (not on replit) and one of the things we need to do is loop through n number of .txt files. Since the number of files will change while the program is running, I can't just put the file names into a dictionary or list and loop through it.

Answered by Coder100 (18872) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18872)

Well, you can't just loop through an n number of files, you have to know what files they are!

Here's something:
https://careerkarma.com/blog/python-list-files-in-directory/

tankerguy1917 (178)

@Coder100 Oh ok, thanks. I think this is exactly what I was looking for.