Ask coding questions

← Back to all posts
Is there a way to get all the names of the text files in Python library?
ChezCoder (84)

I am creating a coding language using Python and the user can select which file to compile from a list. So here's the problem, since I am displaying the available options, I need to get them first but I don't seem to know how to do it... Google doesn't help as it just returns things like "how to get lines from a text file" or "how to clear a text file" which won't help me...

If you know the answer and want to colab with me, just comment and I will invite you!

Answered by mat1 (2881) [earned 5 cycles]
View Answer
Commentshotnewtop
mat1 (2881)
import os
os.listdir('directory')  # leave directory empty if you want to check the main one