list all the files in the current directory in python

To list all the files in the current directory in Python, you can use the os module.

main.py
import os

files = os.listdir()

for file in files:
    print(file)
68 chars
7 lines

The os.listdir() function returns a list of all the files and directories in the current working directory.

In the loop, we simply print each file name one by one. This code should work to list all the files in the current directory.

related categories

gistlibby LogSnag